We are looking for a way to convert the Drupal pages into PDF on click of a button for D8. Initially we thought we could use Print Module, but that only has a D7 version.

How do you create a button in D8 so that on click, it will convert the Drupal node into a PDF keeping the current theme styling and elements appropriately? We have been unable to find any D8 modules or process that can allow for this.

  • 1
    You’re looking for Entity Print. If you have some technical skills, you might be able to implement a print service like AthenaPDF. – Kevin Jan 8 at 22:27
  • If the requirement is to print each pages, then use javascript code : <a class="print-button" href="javascript:window.print()">print</a> – sarika Jan 9 at 4:59
  • @Kevin when i reviewed AthenaPDF it looks like there is a version available for a Docker image. Do you know if it works on a Drupal instance? I cannot find any documentation outside of ones found on Docker's site regarding it – usernameabc Jan 19 at 16:56
  • 1
    It acts as a microservice, so you would run it in its own instance and call its API when necessary to return a PDF. I think it can also be run on-demand on the same server, but its been a while since I tried. – Kevin Jan 19 at 17:08
  • @Kevin i am going to research the on-demand approach to see if i can get that to run because not sure we can get a new instance. thanks for the suggestion. – usernameabc Jan 19 at 20:13
up vote 2 down vote accepted

You can achieve with several solutions

Use Entity Print Module

Entity Print allows you to print any Drupal entity (Drupal 7 and 8) or View (Drupal 8 only) to PDF.

The module is lightweight compared to other modules like the Print module, has full test coverage and is ready to be used in production for both D7 and D8.

Use new host of print module (Printable Module)

This is the new home of the print module. The module makes use of pdf_api module to generate PDFs.

Use PrintFriendly Module (it supports localization very good)

The #1 Print and PDF button for your Drupal site. Printer Friendly pages without coding, css, or print.css. Fast, easy, and professional.

The Print Friendly & PDF button saves paper and ink when printing or creating a PDF. It's fast, easy, and looks great when printed. Add the button now, and your users will see the difference.

How Print Friendly & PDF Works The Print Friendly & PDF button automatically creates printer friendly and PDF versions of your pages without the hassle of having to create a print CSS file. No coding, hacking or programming required. Simply install the Print Friendly & PDF plugin, activate, and choose settings for full customization. It also gives your user the ability to remove images and paragraphs of text, so they really only have to print exactly what they want.

And final solution is kind of tricky solution, instead of converting the page to PDF just provide a print theme style for your nodes, when a user clicks on the print button (or link) trigger javascript:window.print() action. most of the new OS has PDF printer build-in

By the way, I recommend PrintFriendly Module

  • I am testing the entity_print module and have not found a good way to theme it. I will test the other modules as well. – usernameabc Jan 10 at 17:33
  • @user2951257 ,good, inform me with the new results. – Yusef Mohamadi Jan 10 at 18:17
  • i have found a way to theme the entity_print module. I tried the others but since entity_print provides a PDF view mode this will suffice for my needs. – usernameabc Jan 10 at 23:14
  • I do agree that PrintFriendly is good, but our use case is to download the PDF right away. PrintFriendly gives a popup which may not be acceptable by the product owner. – usernameabc Jan 10 at 23:37
  • @user2951257 there isa configuration to achieve it. – Yusef Mohamadi Jan 11 at 10:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.