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

Print Article button

Started by Michael Schapira 5 years ago · 2 replies · 765 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 jean-louis67, 3 days ago
2 82 2 days ago
General · by Andy Miller, 7 days ago
0 146 7 days ago
General · by Veehem, 1 week ago
0 146 1 week ago
General · by milkboy, 1 week ago
0 140 1 week ago
General · by ian russell, 2 weeks ago
2 226 2 weeks ago