[Tex/LaTex] How to make the PDFs produced by pdfLaTeX smaller

file sizepdfpdftex

I feel that the PDFs produced by pdflatex are too huge. So for example my 50 page book with no illustrations is 500KB. I feel it should be more like 50K or even less. The .tex files together are just 40KB. Anyone knows why the final PDF is so huge and is there a way to compress it to make smaller?

Best Answer

A common approach is to let Ghostscript (gs) optimize and compress the PDF after it has been created with pdflatex.

Ghostscript is installed by most Linux distributions and easily available for other platforms (Windows as binaries, MacOS via MacPorts). In fact, almost all size-optimizing tools for PDF (save for Acrobat) you can find on the internet, internally use Ghostscript -- so you can as well call it directly.

There is a plethora of options available; I personally use the following:

 gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dPrinted=false -sOutputFile=foo-compressed.pdf foo.pdf

I use this mostly for beamer presentations, where it gets me a size reduction of 60–70 percent. (A 10 MiB lecture note becomes 3–4 MiB in size.)

Edit 2020-02-06: Added -dPrinted=false to preserve Hyperlinks.
Edit 2020-09-10: Changed -dCompatibilityLevel from 1.4 to 1.5 as pdflatex outputs PDF 1.5 by default since 2010.