WKHTMLTOPDF vs Headless Chrome – PDF Size Comparison

August 6th, 2018 / by api2pdf /

Our mission at API2PDF is to help developers use AWS Lambda to generate PDFs from HTML as cheaply and quickly as possible.  Our two most popular rendering engines are WKHTMLTOPDF and Headless Chrome.

Goal: Find out when it is cheaper to use WKHTMLTOPDF vs Headless Chrome.

Testing Methodology
In our analysis today we are going to stick to PDFs that will be rendered virtually identically from both engines.  Next week, we’ll do a follow up post on rendering differences between the two engines.  To perform the tests we will use create github gists with sample HTML.  We will then use rawgit to generate a public URL like this.  From there we will send it to both WKHTMLTOPDF url and Chrome Url endpoints.

We will use only the URL, with no further parameters.  For example, the HTML snippet above will POST as.

{
"url": "https://cdn.rawgit.com/bootleg224/b8a740d3ace1489ffa101e3e5f26e54a/raw/ccfb942810e4183da6463bcab151a7f7cd8b8419/QuickStartGuide.html",
}

The Results

Let’s take a look at the results.

Sample 1 Sample 2 Sample 3 Sample 4
WKHTMLTOPDF 0.019 MB 0.007 MB 0.290 MB 0.169 MB
Chrome 0.071 MB 0.025 MB 0.334 MB 0.731 MB

In all cases we tested we found WKHTMLTOPDF to generate smaller PDFs when compared to Chrome.  We also could not find a visible difference between the two PDFs generated.  In most cases PDFs were 3x smaller when using WKHTMLTOPDF, but in Sample #3 we threw a lot of data at both engines and we saw Chrome generate PDFs that were only larger by a margin of less than 5%.

Conclusion
Converting HTML to PDF through Api2Pdf is dirt cheap any way you look at it.  Even sample #4 which has the widest margin means $0.000169 per PDF vs $.000731 per PDF.  Unless you are generating tens of thousands of PDFs you probably won’t see a difference to your pocketbook.  Nevertheless, the results are interesting enough to warrant testing your PDF workloads on both engines.  If you can’t tell a visible difference, might as well save money in the long run and use WKHTMLTOPDF.

We released the Chrome endpoint for a reason, the WKHTMLTOPDF engine simply cannot handle as much as Chrome.  We will follow up with another article explaining the differences in the rendering engines with some real world examples.

Read on if you wish to see our actual sample data used for this article.

 


Sample 1: The Api2Pdf Quick Start Guide
This is the default HTML on our home page UI.  This is an example of a quick one page guide that uses a few fonts and basic images (like a logo).

Sample 2: AnyCharts embedded in PDF
This is the same example we blogged about a few weeks ago.

Sample 3: Large Test
This HTML takes 5,000 lines of HTML with a base64 copy of the Api2Pdf Logo repeated dozens of times.

Sample 4: Large Image
This HTML takes a sample image from Unsplash and renders it into a PDF.

Tags: , , ,

Comments are closed.