Using HTML52PDF to create text documents in PHP

I’ve been trying out different PHP libraries to generate text documents. My previous post Using PHPWord to generate text documents in PHP describes my quest in more detail.

This time around I’m tying out the HTML52PDF library ( Despite what it’s name suggests the library is not PDF specific and actually supports the Open Document format directly. The library is actively being developed. It’s website is nice looking, has tutorials and documentation. The only downside is that using the library for commercial use requires a license that starts at $199, but if the library provides what the website claims it would be well worth it.

The demo I created to test the library is available here

The first problem I ran into with the library is that it generates a strict standards level error when you try to create a document. To get around the problem I disabled error reporting of non fatal errors around the render document function call. After that the document would render, but it’s very surprising that a commercial library would have such a obvious problem in the code.

Open Document Format

The Open Document file rendered pretty well except it striped out text that was not wrapped in an HTML tag. This is a problem because that is how most of the text is returned by the Dojo HTML Editor (using Firefox). It is interesting that the PHPWord library had a similar problem.

Open Document Text file generated by HTML52PDF screen capture

screen capture of Open Document Text file generated by HTML52PDF

Portable Document Format (pdf) & Office Open XML (docx)

To generate PDF, Office Open XML or RTF documents the library requires LibreOffice to be installed on the server and setup to use an extension included in the HTML52PDF library and then to run an additional PHP script as a service which translates the Open Document file into another format with LibreOffice. I set this up on my development server, but my first attempt generated additional warnings and errors when I tried to generate formats other than Open Document. After changing where I was saving the files from the system temporary folder to a folder with different permissions and tweaking the service script. I was able to generate other formats. I decided against going through the same process on my production server so the demo does not production Office Open XML (docx) or PDF files.


It’s really hard to feel confident in a library that generates warnings using its most basic functions. Even though the warnings don’t prevent the library from functioning it makes me question how much testing went into its release and spending $199 on licensing software that has such obvious defects.

The dependency on LibreOffice libraries to generate formats other that Open Document seems problematic as it means extra setup on a production server and may introduce compatibility issues with later versions of LibreOffice. The PHP script that you have to run as a service gave me additional concerns. First the library doesn’t provide any tools to launch the script which means additional server setup and maintenance. It also means that if the script crashes, rendering formats other than Open Document will stop working without any warning, unless you setup some kind of monitoring solution to check that the script is runing. Finally the libraries installation guide recommends running the script as root which is an obvious security vulnerability. If I did go ahead with using this software I think I would only use it to generate Open Document files, but that seriously reduces it usefulness.

In the end the library does to a good job rendering Open Document Text files, but there are several issues that make it difficult for me justify the $199 it costs to license it.


Leave a Reply

Your email address will not be published. Required fields are marked *