We created the DocRaptor HTML-to-PDF API over a decade ago because none of the existing conversion libraries met our needs. We still believe it’s the best PHP PDF conversion tool available, though that doesn’t mean DocRaptor is the best option for every PHP project.
Below is a review of the most common PHP PDF generators, both commercial and open-source libraries. We’ll review their general strengths and weaknesses, but we haven’t used all of these tools in a production environment. Please do your own research. PDF generation is complicated and unique to every situation and document. This article is merely a starting point.
PDF conversion tools should be analyzed across a few dimensions:
With all that said, here’s the list:
As the only API powered by Prince HTML-to-PDF engine (more on Prince below), DocRaptor generates high-quality PDFs with the most raw power, flexibility, and advanced HTML/CSS functionality. In addition to our unmatched conversion ability, we guarantee 99.999% uptime and are trusted by major organizations worldwide, including Shopify, HubSpot, Square, The Linux Foundation, and hundreds more.
Our PHP HTML-to-PDF agent can be installed in minutes, and you can start testing without an account. When you’re ready to sign up, DocRaptor has a free plan along with commercial plans starting at just 25c/document or $15/mo.
Prince, formerly known as PrinceXML, is the market leader in HTML-to-PDF conversion software. It pioneered the HTML-to-PDF concept, and Håkon Wium Lie, the inventor of CSS and CTO of Opera, serves as Chairman of the company. The company’s software provides a lot of unique functionality for advanced PDF use cases, like headers and footers, page numbers, generated content, and much more. DocRaptor uses Prince for our PDF generation. Prince pricing starts a $3,800/server and has a PHP wrapper.
If you cannot afford DocRaptor, we generally recommend a Chromium-based library. These libraries have the ease of HTML-based conversion and still have the modern HTML and CSS functionality of Google Chrome. The downside is that Chromium does not support DocRaptor’s level of PDF-specific functionality, like accessible PDFs, advanced page-break control, advanced headers, footers, etc.
It's also important to remember that generating PDFs through a browser requires running the browser on your server, which is more CPU- and resource-intensive than most web server tasks. For a small number of PDFs, this isn't a big deal. But if you need to make lots of PDFs quickly, you'll need more servers to scale your efforts.There’s a wide variety of Chromium-based libraries available, including:
Chrome PHP runs the Chromium executable directly and provides an API for accessing the headless browser. Simply navigate to the desired page and run a `$page->pdf()->saveToFile('/foo/bar.pdf');` command. This library is fairly popular and seems well supported.
PuPHPeteer takes a different approach than Chrome PHP. Puppeteer is the most popular Headless Chrome library and is supported directly by Google, but it's based in Node. PuPHPeteer uses Rialto as a bridge to interact directly with Puppeteer. The advantage of PuPHPeteer is that you benefit from the full community and corporate support of Puppeteer. However, the downsides are the same, fewer PDF generation features and more resource usage.
While Chromium is the most modern browser engine available in an HTML to PDF library, some libraries are using older (much older) versions of Webkit:
WkHtmlToPdf is based on an old version of Webkit (Safari’s engine). You can access wkhtmltopdf through the phpwkhtmltopdf wrapper library. We don't recommend it for anything other than the most simple of PDFs. Generally speaking, Chrome Headless-based browsers are more powerful with support for modern CSS functionality, such as Flexbox.
Do not use PhantomJS. While it was widely used for many years, the browser is very outdated, and the library is now unmaintained. We've included PhantomJS in this list only to warn you against it.
TCPDF is one the oldest and most popular PHP PDF creators, also based on FPDF. Unlike most of the HTML-based tools discussed in this article, with TCPDF, you create your PDF element by element, image by image, text line by text line. As a result, it’s possible to create almost any PDF you'd like; it just might take more effort than using HTML. You can even create varying headers or page sizes within the same document, but it requires writing custom PHP functions (whereas in DocRaptor, it's simple CSS). Unfortunately, the TCPDF's documentation is abysmal, which further complicates the implementation process.
PDFCrowd is probably the most widely-used HTML-to-PDF API, with free browser plugins, WordPress plugins, and more. It has a native PHP client and inexpensive pricing. The downside is that it uses the Headless Chrome engine for PDF generation, meaning it has all the same problems that Headless Chrome has in general. It lacks the PDF-specific functionality that DocRaptor and some of the other tools provide.
There are many other commercial HTML-to-PDF APIs available, many with PHP clients. All of them, except for DocRaptor, use open-source libraries to generate PDFs. Frankly, if you're considering an online HTML-to-PDF API, your choice will come down to power and trust vs. cost. DocRaptor, with the Prince PDF engine, enables far more complex PDFs and easier implementation. And as you can see from our testimonials page, our reliability and scalability are trusted by the largest organizations in the world.
There are few truly bad PHP options for generating PDFs -- merely some options that will meet your needs and some that won't. Consider the following questions when evaluating PHP PDF generators:
We hope this helps! If you have any follow-up questions, feel free to contact us at email@example.com.