How to reduce PDF file size – Part 2

Several months ago, I wrote a blog post about reducing a PDF file’s size. Since then, I’ve used that technique many times. However, you may want to control the DPI (dots per inch) even more specific. Here’s how to do it:

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 \
-dDownsampleColorImages=true \
-dDownsampleGrayImages=true \
-dDownsampleMonoImages=true \
-dColorImageResolution=120 \
-dGrayImageResolution=120 \
-dMonoImageResolution=120 \
-sOutputFile=output.pdf input.pdf

5 thoughts on “How to reduce PDF file size – Part 2”

  1. One different technique that worked for me on some pdf’s is a script like this:

    #!/bin/bash
    pdf2ps “$1” /tmp/shrink_pdf_tmp.ps
    ps2pdf /tmp/shrink_pdf_tmp.ps “$1”

    I think this works especially well when the software that generated the PDF in the first place, didn’t do a good job optimizing it. YMMV, though…

  2. Thanks for the script.
    How can I adapt it that it will otimise all the files in a folder, or even recursively?

    1. Hi Renate, please try this (and have a backup at hand… just in case…):

      find . -iname ‘*.pdf’ -exec sh -c ‘gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 -sOutputFile=”{}_new” “{}”; mv “{}_new” “{}”‘ \;

      1. I used the script on my Linux server as above, but it gives the following error message:
        find: missing argument to `-exec’
        mv: target `;’ is not a directory

        What could the error be? Please advise.
        Thanks
        Renate

        1. Hi Renate,
          please make sure the quotation marks are correct. My blog seems to replace them… So please replace ” and ‘ with the standard characters before executing the command.
          Kind regards,
          Heiner

Leave a Reply

Your email address will not be published. Required fields are marked *