Sign up ×
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
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
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
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

3 Answers 3

up vote 77 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 plethora 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 10 MiB lecture note becomes 3–4 MiB in size.)

share|improve this answer
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
@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
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

Here is a revised version of the script above. The basics are unchanged, but it now handles paths and such in a sane manner, automatically copies the new over the old IFF the new file is smaller then the original (and not 0). It also gives some info on space savings. For some unknown reason, running it again can give even smaller output, but usually not by much. The first run gives the big speedup.

For example:

ekl@Taro:~/Documents⟫ optpdf techResume.pdf 
Saving 1245351 bytes (now 6% of old)
ekl@Taro:~/Documents⟫ optpdf techResume.pdf 
Saving 31 bytes (now 99% of old)
ekl@Taro:~/Documents⟫ optpdf techResume.pdf 
Saving 7 bytes (now 99% of old)
ekl@Taro:~/Documents⟫ optpdf techResume.pdf 
Didn't make it smaller! Keeping original

It is legal to give it long paths, but it currently doesn't like spaces in your filenames. Sorry. Getting shell scripts to handle this correctly in all instances is a pain, so just don't don't do it.

Here is the code:

# optpdf file.pdf
#   This script will attempt to optimize the given pdf
filebase=$(basename $file .pdf)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH \
        -sOutputFile=${optfile} ${file}
if [ $? == '0' ]; then
    optsize=$(stat -c "%s" ${optfile})
    orgsize=$(stat -c "%s" ${file})
    if [ "${optsize}" -eq 0 ]; then
        echo "No output!  Keeping original"
        rm -f ${optfile}
    if [ ${optsize} -ge ${orgsize} ]; then
        echo "Didn't make it smaller! Keeping original"
        rm -f ${optfile}
    bytesSaved=$(expr $orgsize - $optsize)
    percent=$(expr $optsize '*' 100 / $orgsize)
    echo Saving $bytesSaved bytes \(now ${percent}% of old\)
    rm ${file}
    mv ${optfile} ${file}


share|improve this answer
Nice that you output actual numbers. For a text only document of about 40 pages (created by ConTeXt), I get a reduction of only 2% in size; but for a 50 page presentation (again created by ConTeXt with lots of images and colors), I get a 40% reduction in size. – Aditya Sep 2 '14 at 17:47
I'm not sure why running it again will reduce it in size more. Its a ghostscript issue. But, its usually the first run that does the big lifting. Its safe to run it over and over - I even considered doing a loop to run it until it won't reduce any more. – Evan Langlois Sep 20 '14 at 6:49
If you get errors like stat: illegal option -- c and line 14: [: : integer expression expected, you must change stat -c "%s" into stat -f "%z" in lines 12 and 13. – Jonathan Jun 14 at 10:26

There is a wonderful script to shrink a PDF: . I've been using it for years and can recommend it. The main effect is that it compresses the embedded fonts. Very helpfull if a font is large, like Linux Libertine. The script shrinks such a PDF (if no pictures are included) to 10% of the size!

Using it under Windows requires carefull installation to get all the necessary *.dll files.

Once in a while the script quits with an error message. The most frequent reason is that Multivalent has an issue. Simply avoid multivalent with the command --use-multivalent=false ... .

Another issue comes up, if you include other PDFs made by pdftex. Sometimes -- especially with Linux Libertine -- the italic letters in the included PDFs get garbled. We can avoid this by adding as first line to the *.tex file: \pdfinclusioncopyfonts=1.

share|improve this answer
@ Keks Dose. I have a pdf file (18MB) generated by Texify->dvi-pdf, including many .eps figs. I tried to use pdfsizeopt you recommended to reduce its volume to be less than 3MB. With the commandline: c:\ pdfsizeopt\pdfsizeopt --use-multivalent=false --do-unify-fonts=false c:\pdfs\manuscript.pdf. It turns out that it only reduces the input-pdf by 1% or so. Can you give me some further advice? – lxy Jul 18 at 10:20
@lxy Many ways. Obviously: reduce the size of the pics before including them, without that, you won't get far. Use multivalent, instead of =false. If available, use Adobe Pro to shrink the size. – Keks Dose Jul 18 at 11:02
@ Keks Dose. Thanks! However with --use-multivalent=true, cmd gives me error Multivalent.jar not found... – lxy Jul 18 at 11:49
@lyx Well, you'll probably have to install it. The correct way depends on your OS. There used to be a manual by the author of pdfsizeopt. – Keks Dose Jul 18 at 22:43

Your Answer


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.