# Performance of wkhtmltopdf

We are intending to use wkhtmltopdf to convert html to pdf but we are concerned about the scalability of wkhtmltopdf. Does anyone have any idea how it scales? Our web app potentially could attempt to convert hundreds of thousands of (reletively complex)html so it's important for us to have some idea. Has anyone got any information on this?

-

First of all, your question is quite general; there are many variables to consider when asking about scalability of any project. Obviously there is a difference between converting "hundreds of thousands" of HTML files over a week and expecting to do that in a day, or an hour. On top of that "relatively complex" HTML can mean different things to other people.

That being said, I figured since I have done something similar to this, converting approximately 450,000 html files, utilizing wkhtmltopdf; I'd share my experience.

Here was my scenario:

• 450,000 HTML files
• 95% of the files were one page in length
• generally containing 2 images (relative path, local system)
• tabular data (sometimes contained nested tables)
• simple markup elsewhere (strong, italic, underline, etc)
• A spare desktop PC
• 8GB RAM
• 2.4GHz Dual Core Processor
• 7200RPM HD

I used a simple single threaded script written in PHP, to iterate over the folders and pass the html file path to wkhtmltopdf. The process took about 2.5 days to convert all the files, with very minimal errors.

I hope this gives you insight to what you can expect from utilizing wkhtmltopdf in your web application. Some obvious improvements would come from running this on better hardware but mainly from utilizing a multi-threaded application to process files simultaneously.

-
FYI for anyone who doesn't like to do math, that averages to 480ms per doc –  Derek Dahmer Sep 2 at 20:01

In my experience performance depends a lot on your pictures. It there are lots of large pictures it can slow down significantly. If at all possible I would try to stage a test with an estimate of what the load would be for your servers. Some people do use it for intensive operations, but I have never heard of hundrerds of thousands. I guess like everything, it depends on your content and resources.

The following quote is straight off the wkhtmltopdf mailing list:

I'm using wkHtmlToPDF to convert about 6000 E-mails a day to PDF. It's all done on a quadcore server with 4GB memory... it's even more then enough for that.

There are a few performance tips, but I would suggest trying out what is your bottlenecks before optimizing for performance. For instance I remember some person saying that if possible, loading images directly from disk instead of having a web server inbetween can speed it up conciderably.

Edit: Adding to this I just had some fun playing with wkhtmltopdf. Currently on an Intel Centrino 2 with 4Gb memory I generate PDF with 57 pages of content (mixed p,ul,table), ~100 images and a toc takes consistently < 7 seconds. I'm also running visual studio, browser, http server and various other software that might slow it down. I use stdin and stdout directly instead of files.

-
PLUS ONE for the images from disk instead of web server in between. I just tested it and saved 70% of generation time ! –  np87 Mar 31 at 12:21

We try to use wkhtmltopdf in any implementations. My objects are huge tables for generated coordinate points. Typically volume of my pdf = 500 pages

We try to use port of wkhtmltopdf to .net. Results are

- Pechkin - Pro: don't need other app. Contra: slow. 500 pages generated about 5 minutes
- PdfCodaxy - only contra: slow. Slower than pure wkhtmltopdf. Required installed wkhtmltopdf. Problems with non unicode text
- Nreco - only contra: slow. Slower than pure wkhtmltopdf. Required installed wkhtmltopdf. Incorrect unlock libs after use (for me)


We try to use binary wkhtmltopdf invoked from C# code.

Pro: easy to use, faster that libs
Contra: need temporary files (cannot use Stream objects). Break with very huge (100MB+)html files as like as other libs

-
Regarding NReco.PdfGenerator, I have no idea how it can be slower than pure WkHtmlToPdf (internally it invokes WkHtmlToPdf.exe in separate process). Also it does NOT require installed WkHtmlToPdf: all files are embedded into DLL and extracted automatically if missed. –  Vitaliy Fedorchenko Sep 10 at 16:12