Exporting Practically Anything in Drupal to PDFs

May 31, 2016
2
PDF icon

Have you ever been asked by a client to export pages or content as a PDF?

Yeah, I know that feeling.

I think this is one of the most underestimated development tasks in the non-technical world. It is not that easy, and it is even harder to explain.

What tool should I choose? Is it compatible with the OS of the host site? Is there a module for that?

Ok, it’s not impossible, but it’ll take time…

Probably more than what your client is willing to pay…

And then, the problem usually appears in those special cases: when you need to export that “example” form (that won’t be submitted), or a 100% JS quiz…

Generating that HTML on the server side, when the logic is on the client side, is hard to achieve. You may be thinking that you’ll need to duplicate the logic so you can recreate the same scenario the end user has on his screen.

Fortunately, you don't have to go that route: PDF Export is here, transforming this process into a few simple steps:

  • Download and install the module
  • Choose what library to use, and download dependencies
  • Add a PDF Export button to your view/node/page
  • That’s it!

Look at the following example of an HTML page exported into a PDF file using this tool:

image02_1.png
Views Table exported with PDF Export module using Bartik theme including the print css file.

Customization

You just can simply use the theme’s CSS, but PDF Export also offers some useful customizations:

  • CSS Files
    Define multiple css files from your theme, also include a print.css file if you want.
  • HTML
    Implement hook_pdf_export_html_alter(&$html, $filename) for a customized cover or url rewriting.
  • Selectors
    You have total control of what is going to be exported, just enter the jQuery selectors you want to export.

image00_3.png
Configuration form of the views area plugin

Images not showing up because of your basic authentication? No problem, PDF Export solves it for you.

Some PDF generators try to use http instead of simply looking for your files in the filesystem. So you have to use absolute urls, since you need to include your basic authentication credentials on the on the url.

PDF Export will do the hard job, enable the basic auth rewrite, and it will lookup the credentials from the $_SERVER variable, rewriting all the urls to the correct domain.

In case you need anything else, or use another domain, you can simply configure it on the module:

image01_4.png
PDF export settings

Upcoming enhancements

  • PDF Export is in active development, sponsored by CI&T. Stay tuned for these upcoming enhancements:
  • PDF Export: Node
  • Blocks with custom export PDF buttons
  • Integration with wkhtmltopdf

Don’t hesitate to post your own feature request in the module’s issue queue.

Sign-up for our Developer Blog Newsletter

Thanks!

Add comment

By submitting this form, you accept the Mollom privacy policy.