Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up wkhtmltopdf and pdfkit for long webpage with lots of photos

We are having wkhtmltopdf convert html that results in hundreds of pdf pages with hundreds of large photos, on a ec2 small instance this takes about 10 minutes per conversion. The time taken is definitely due to the large amount of photos, if taken out the conversion happens in a few seconds.

are there performance tweaks I can do to speed up wkhtmltopdf? is it cpu bound or io bound? would it be possible to have place holders put in and then be replaced by the photos afterward?

like image 664
Kalendae Avatar asked Apr 26 '11 17:04

Kalendae


1 Answers

You might be spending too much time making http requests for the images themselves.

If your html looks like this:

<img src="http://someserver.com/images/000000001.jpg"/>

Perhaps try filesystem loading like this:

<img src="file:///users/images/00000001.jpg"/>

Also, if possible, try to specify width and height's on your images, that should speed up rendering a bit.

But I'm afraid the real issue is probably the amount of memory and IO you are limited to on your small instance. Try and benchmark on a local system, it will probably be much much faster.

like image 150
Unixmonkey Avatar answered Oct 02 '22 06:10

Unixmonkey