Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Print Article button

Started by Michael Schapira 5 years ago · 2 replies · 632 views
5 years ago

Hi grav community.

I am using grav as an easy way to write article / documentations.
Some time I may need to share the content as PDF instead of the direct link to the page.

I am thinking I would need to add a button on the page that would generate the PDF, but also change the theme / layout to make it printer friendly (remove header, nav bar etc ).

Looking for some advices on how I could implement that.

Thanks.

5 years ago

There maybe something already written to achieve this.

Try SnappyGrav plugin, in the plugins manager or maybe look at paul hibbits theme 'open publishing' in the theme directory / skeleton as you might be able to use his structure to achieve your goal.

:)

5 years ago

Hi Antineutrinos,

Personally when I've had to do print versions of html pages I do with with print media queries in css.

Smashing Magazine has a good intro to the topic:
https://www.smashingmagazine.com/2011/11/how-to-set-up-a-print-style-sheet/

EDIT:
For the actual button to print you could do this with javascript as such:

JS
<button id="printBtn"> print me </button>

<script type="text/javascript">
  document.getElementById('printBtn').onclick = function printContent() {
    window.print()
  }
</script>

See more on Mozilla Web Docs:
https://developer.mozilla.org/en-US/docs/Web/API/Window/print

Hope that helps

👍 1
last edited 06/19/21 by modal mouse

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 95 14 hours ago
General · by pamtbaau, 19 hours ago
1 61 19 hours ago
General · by Andy Miller, 1 day ago
0 47 1 day ago
General · by Marcel, 12 months ago
6 356 5 days ago
General · by Duc , 6 days ago
3 44 6 days ago