4

I noticed that when compiling any document in TeX, the resulting PDF can be reduced in size by quite much. For example, take

\documentclass{article}

\begin{document}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.

\end{document}

and compile it with

$ lualatex test.tex
$ du -h test.pdf 
16K    test.pdf

GhostScript can then decrease the file size by half, e.g.,

$ gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/default \
-sOutputFile=out.pdf test.pdf
$ du -h out.pdf 
8.0K    out.pdf

I'm experiencing the same behavior for all documents I tried, no matter how large or complex they are.

Are there (La)TeX commands that optimize the PDF in a similar way straight from {lua,pdf}(la)tex?

  • 3
    What version PDF are you producing? Are you using microtype? Etc. Without knowing anything about your setup it is hard to say. But pdfTeX, at least, is not generally configured to optimise the size of the resulting document. – cfr Mar 04 '15 at 01:41
  • @cfr The phenomenon occurs for all documents I've tried, even the most simple ones. I updated the question accordingly. – Nico Schlömer Mar 04 '15 at 07:47
  • 6
    Typically the answer here is no, as (La)TeX builds the document from scratch each time, not knowing what might come further down the line. (La)TeX walks somewhat blindly through the document while it's constructing the output page-by-page. GhostScript actually post-processes the document, perhaps consolidating dictionaries and removing some duplication, leading to a more slender result. – Werner Mar 04 '15 at 07:56
  • 2
  • 2
    You get even a smaller PDF file with OpenType fonts and LuaTeX or XeTeX by adding \usepackage{fontspec} (default: Latin Modern fonts). OpenType fonts are not encrypted as Type 1 fonts and can therefore be better compressed. – Heiko Oberdiek May 20 '15 at 07:41
  • 2
    I think it is important to distinguish three very different types of size optimization in discussion : a) lossless - where the file "output" is essentially identical, b) Lossy - where file output might be compromised in some way (image resolution or compression compromised), c) Lossy but irrelevant (e.g. image size reduced but still above printer resolution). For most truly massive documents the majority of size is down to images. As far as I know LaTex stores duplicate image useages only once. – Aubrey Blumsohn May 20 '15 at 09:04

0 Answers0