htmlmacospdfsizewkhtmltopdf

Any Way to Reduce File Size Using wkhtmltopdf?


I am using wkhtml in OS X to convert an HTML file to a PDF. I am able to do this successfully using the code

/usr/local/bin/wkhtmltopdf sample.com --zoom 0.65 /Users/dwm8/Desktop/sample.pdf

My problem is that the file is rather large, coming in at about 500 KB. Is there any way to shrink the file size? All I am interested is the visual contents of the page (I would be fine taking a screenshot of the website if I didn't have to do it manually), and I don't care about all of the hyperlinks or other website features showing up in my PDF.


Solution

  • The flag that works best for me in reducing file size is

    --image-dpi 300

    As the default DPI is 600, this can reduce the filesize of an image-heavy PDF by 75% and is still good enough for most purposes.

    There are two other flags you can use:

    --lowquality - supposedly makes it smaller

    --image-quality 80 - jpeg compression, default is 94

    but overall I find the DPI makes the biggest difference, and if you aren't printing to 600dpi or zooming then you're not really losing anything.

    For your use case also try

    --no-outline - as you likely don't need a contents section

    and the self-explanatory

    --disable-internal-links

    --disable-external-links

    but these are likely to be smaller wins.