2020-10-27 Shrink PDF

Got a scanner. Scanning documents. 2MB for a black and white document is too big! Found a solution online:

pdf2ps -dLanguageLevel=3 document.pdf
mv document.pdf document.pdf~
ps2pdf -dPDFSETTINGS=/ebook document.pdf

The first command generates a postscript (PS) file, the second command renames the PDF file, and the third command generates a PDF from the PS file using the ebook settings. The result is that my 1.9M file shrunk to 343K.

Shrink PDF size with this command line trick

​#Publishing

Comments

(Please contact me if you want to remove your comment.)

How is the quality of the smaller PDF?

– Unnamed 2020-10-27 20:49 UTC

---

This messes up (or rasterizes) any alpha transparency layers in the PDF.

– Sandra Snan 2020-10-28 08:18 UTC

---

Of course. And colors are lost, dpi is reduced to 150, and probably more stuff. But it’s a legible copy of the document and so I’m happy. This was a “please send us a copy of this document” situation.

– Alex Schroeder 2020-10-28 09:53 UTC

---

Just using ps2pdf on the pdf usually works great

– Isidoro 2021-01-27 19:25 UTC

function pdf-shrink --description 'Turn images in PDF files to 150dpi JPG'
# https://ghostscript.com/blog/optimizing-pdfs.html
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH \
   -dConvertCMYKImagesToRGB \
   -dGrayImageFilter=/DCTEncode -dColorImageFilter=/DCTEncode \
   -dAutoFilterGrayImages=false -dAutoFilterColorImages=false \
   -dDownsampleColorImages=true -dDownsampleGrayImages=true -dDownsampleMonoImages=true \
   -dColorImageResolution=150 -dGrayImageResolution=150 -dMonoImageResolution=150 \
   -dColorImageDownsampleThreshold=1.1 -dGrayImageDownsampleThreshold=1.1 -dMonoImageDownsampleThreshold=1.1 \
   -dPreserveHalftoneInfo=false -dPreserveOverprintSettings=false \
   -dTransferFunctionInfo=/Apply -dUCRandBGInfo=/Remove \
   -sOutputFile=$argv[2] $argv[1]
end