2

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.

dwm8
  • 309
  • 3
  • 16

2 Answers2

8

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.

Paul Gregory
  • 1,733
  • 19
  • 25
-1

Well if you are just after an image, you could instead use wkhtmltoimage. This may end up with a reduced filesize, not sure though.

Also a couple of other solutions to generating images from pages listed here:

Website screenshots using PHP

Community
  • 1
  • 1
Tom Folk
  • 123
  • 7