Sunday 6 January 2019

How to compress scanned PDF?

One problem with scanned pdfs is that the size is so bloated. One good solution to compress such files is this one script:

#!/bin/sh

gs  -q -dNOPAUSE -dBATCH -dSAFER \
    -sDEVICE=pdfwrite \
    -dCompatibilityLevel=1.3 \
    -dPDFSETTINGS=/screen \
    -dEmbedAllFonts=true \
    -dSubsetFonts=true \
    -dColorImageDownsampleType=/Bicubic \
    -dColorImageResolution=120 \
    -dGrayImageDownsampleType=/Bicubic \
    -dGrayImageResolution=72 \
    -dMonoImageDownsampleType=/Bicubic \
    -dMonoImageResolution=120 \
    -sOutputFile=out.pdf \
     $1


Here the compression rate can be changed by tweaking resolution values. I found the above gives a good compression without sacrificing the text quality.