22 July 2014

Compress or optimize PDF size the most optimal way. Most of the PDF size comes from images. Images that might be 2-3 MB in size, but is viewed only as thumbnail. So this reduces the image for optimal size. So it appears to look the same, but the images DPI is reduced. Under the ghostscript I included the variants you can use to get the optimization you need. You can still get a really good optimization, even if you use a sharp 300 dpi.

Source code viewer
  1. # Get ghostscript with your package manager (aptitude, yum, pacman, yaourt);
  2. apt-get install ghostscript
  3.  
  4. # Run ghostscript.
  5. gs -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -dINTERPOLATE -dNOPAUSE -dQUIET -dBATCH -dNumRenderingThreads=8 -r300 -sOutputFile=output.pdf -c 30000000 setvmthreshold -f input.pdf
  6.  
  7. # -dPDFSETTINGS=
  8. # /screen - 72 dpi images
  9. # /ebook - 150 dpi images
  10. # /printer - 300 dpi images
  11. # /prepress - color preserving, 300 dpi
Programming Language: Bash