Sunday, July 22, 2012

A great way of shrinking image-heavy PDF files

I recently had to cut a huge PDF file down to a reasonable size; the images that were included in the original document were huge. I found the following GhostScript commands to be very helpful. They downsample the images without changing any of the associated text.

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile=output.pdf -f input.pdf

One can get images to be smaller with a few tweaks:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dDownsampleColorImages=true -dColorImageDownsampleType=/Average -dColorImageDownsampleThreshold=1.0 -dColorImageResolution=36 -sOutputFile=output_smaller.pdf -f input.pdf
 UPDATE: For e-ink readers, often times, color images are a waste. Here's a way to convert color to grayscale (greyscale?):
gs -q -dNOPAUSE -dBATCH -sOutputFile=grayscale.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibilityLevel=1.4 -f color.pdf

No comments: