Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
13  
1  
It might be useful to know which TeX system you use. There is more compression in modern TeX Live systems, by for example compressing how hyperlinks are constructed. –  Joseph Wright May 24 '11 at 19:51
1  
It's normally mostly the fonts. Also hyperlinks can add to the size if you have many of them. My 10page package manuals jumped from 120k to 460k just for changing the font and the font encoding. –  Martin Scharrer May 24 '11 at 20:20
    
Does the size difference actually matter? The price of 1MB of hard drive storage is somewhere around 0.001 to 0.01 cent (0.1 for SSD). Bandwidth is probably something like 0.00001 (Amazon S3) to 1 cent (AT&T mobile) per MB. (These measurements are of course completely unscientific.) I'd rather have nice fonts and diagrams. –  Caramdir May 24 '11 at 20:50
1  
If you have Acrobat, you can determine how the space is being used by going to Advanced > PDF Optimizer > Audit space usage –  Emre May 25 '11 at 21:18
show 5 more comments

1 Answer 1

up vote 45 down vote accepted

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 pletoria of options available; I personally use the following:

 gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -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 ten MiB lecture note becomes three too four MiB in size.)

share|improve this answer
1  
I wonder if you get the same size reduction if you use \pdfminorversion=5 \pdfcompresslevel=9 \pdfobjcompresslevel=3, i.e. maximum compression with PDF v1.5. –  Martin Scharrer May 25 '11 at 22:39
    
@Martin Scharrer: Not really, with my lecture these options give only a size reduction of 110 Bytes 9825306 no-compression.pdf 9825196 pdflatex-compression.pdf 4318774 gs-compression.pdf 4318772 pdflatex-gs-compression.pdf –  Daniel May 26 '11 at 11:13
    
The numbers before the filename are the actual size. (It kind of bugs me that all newlines get lost when saving a comment...) –  Daniel May 26 '11 at 11:20
1  
@Martin Scharrer: I get interesting results: By setting \pdfcompresslevel=0 \pdfobjectcompresslevel=0 the resulting file size gets smaller (even though only a bit: 9630339 instead of 9825196). Piping this result through gs gives exactly the same size as piping no-compression.pdf through it:4318772. So the bottom line is that (at least for beamer presentations) gs reduces the size quite a bit, independently from the choosen pdflatex compression options. –  Daniel May 26 '11 at 12:04
3  
pdfsizeopt uses this kind of compression through gs as one of the tricks it uses to get smaller PDFs (it also uses a whole tonne of other tricks, so it will generally do better than gs alone). See also this whitepaper on a whole series of techniques for getting smaller PDFs. –  Lev Bishop Jun 6 '11 at 15:41
show 8 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.