Print Article button

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.

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.

:slight_smile:

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:

<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:

Hope that helps

1 Like