Week five and issues with PDF generation

June 30, 2015

This post is about the progress which I have made while porting print module to Drupal 8 as part of GSoC 2015. Below is an excerpts about the work done in week five while work done in week four can be tracked over here.

The week five of coding period ended and as planned I started to work on generating PDF using third party libraries after fixing some errors and code style in the module coded till now. As expected the week turned out to be very eventful and very exciting for me atleast because I really like the idea of interfacing Drupal with external libraries and tools, mainly because it makes Drupal more useful and easier to use.

The first external library which I am using to generate PDFs is wkhtmltopdf. The library is an open source command line tool which renders HTML into PDF. It runs headless and do not require a display or display service. The library is awesome mainly because quality of PDF generated by this is far superior than other PDF generating libraries.

Since the amount of intial work invloved before actually getting a PDF format of HTML content was extensive so I am using a PHP wrapper for the same. I had option of either using phpwkhtmltopdf or snappy. After using both I decided to go with former mainly because of the large number of utility functions provided by the wrapper and easily followable documentation.

Selecting wrapper was only a start, I had initially tested the library using some random HTML document (it didn’t involved interface of Drupal) and the result were as expected. But when I tried to generate PDF via rendering of HTML content generated by twig template a network error kept showing: ContentOperationNotPermittedError

By doing a lot of debugging I came to conclusion that presence of base tag in twig template was causing problem. On removing it the error does not shows up and PDF is generating successfully. Since I think this is problem of binary file of library so I created an issue for same in both wrapper and library repo on GitHub.

Since this week I was able to create plugin for wkhtmltopdf libary so next week I will be focussing on resolving any further issues which I face while using this plugin and also start to work on generating plugin for mPDF library.

Some progress of PDF part of module can be viewed over here and remaining over here.

comments powered by Disqus