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
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…
Thanks for the script.
How can I adapt it that it will otimise all the files in a folder, or even recursively?
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” “{}”‘ \;
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
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