Thursday, November 17, 2016

ghostscript img reduce in pdf

The elephant in the room are the embedded bitmaps, which can blow up the file size really fast. I have a 400 page book manuscript with lots of molecular structures rendered at 600 dpi (for print), and the overall file size is 50 Mb.
I just googled around for a way to reduce the resolution of embedded images and found that ghostscript can do this:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=small.pdf big.pdf
The level of compression is adjusted by the -dPDFSETTINGS switch:
-dPDFSETTINGS=/screen   (screen-view-only quality, 72 dpi images)
-dPDFSETTINGS=/ebook    (low quality, 150 dpi images)
-dPDFSETTINGS=/printer  (high quality, 300 dpi images)
-dPDFSETTINGS=/prepress (high quality, color preserving, 300 dpi imgs)
-dPDFSETTINGS=/default  (almost identical to /screen)
With my file, the down-sampled images produced with the /screen and /ebook settings look very coarse, but the output of the /printer setting looks very nice on screen, while still bringing the file size down from 50 to 13 Mb. Hyperlinks were preserved. So, this seems to be straightforward and viable option.