1

I am generating my PDF document (thesis) with LuaLaTeX. Almost all of my figures are made with the pgfplots package and do not exceed 40 kB. The document is 178 pages. The size of this document is 34 MB. It is too large to upload to our library server.

Even if I exclude all non-PDF images the size does not decrease much. It decreased on the size of png images I'm using.

Is there a way to reduce the quality of the document and compress it? For example: compress all figures...

saldenisov
  • 2,485
  • 3
    (pdf)LaTeX uses a one-pass generation of the output, so there's no optimization of content. You'll most likely find that post-processing using something like Adobe Acrobat would work best, since then it can assess the entire document to find areas of optimization. – Werner Dec 03 '14 at 22:30
  • 5
  • 3
    I don't understand. If all your figures are small where do the 34MB comes from? – Ulrike Fischer Dec 03 '14 at 22:51
  • PDFs produced by XeLaTeX are generally much smaller. – Bernard Dec 03 '14 at 22:56
  • The file size sounds oddly large... makes me wonder what on Earth is in those 178 pages! For comparison, I have a 452 page document from 2007 which is 1.6M. That was using PDF version 1.4. It would be smaller, probably, if I used 1.7 as I usually do now. (It should certainly not be larger.) I can only think that you are including very large PDF images. – cfr Dec 04 '14 at 04:07
  • @cfr not big pdf, just many of them and as well 3D png graphics. – saldenisov Jan 21 '15 at 20:56

2 Answers2

10

Compress settings

Ensure that the compress settings are correct:

\typeout{pdfcompresslevel=\the\pdfcompresslevel}
\typeout{pdfobjcompresslevel=\the\pdfobjcompresslevel}
\typeout{pdfminorversion=\the\pdfminorversion}

Default for TeX Live 2014:

pdfcompresslevel=9
pdfobjcompresslevel=2
pdfminorversion=5

\pdfcompresslevel compresses streams as page descriptions. An enabled \pdfobjcompresslevel (value 1 or 2) compresses further data structures, but requires PDF-1.5.

If you have smaller values, then the values can be set by:

\pdfcompresslevel=9
\pdfminorversion=5
\pdfobjcompresslevel=2

It can be set at the very begin of the TeX file and should be done before the first object is written to the PDF file. You can check later that no package or class has changed the values.

Fonts

OpenType fonts can be much better compressed than Type 1 fonts, because the latter are stored encrypted, which does not compress very well. Since LuaTeX is already used, I assume that the fonts are already OpenType?

The program pdffonts or AR's font information can be used to check the type of the fonts.

Plots

Refer the 40KB to the source of the plots? Then the result in the PDF file can be much larger. With simple commands much output can be generated. Thus it is possible that much of the 34MB is caused by the plots.

Analyzing

A tool like pdftk can be used to split the PDF into single pages to look for pages with large size.

Heiko Oberdiek
  • 271,626
  • Heiko, under which circumstance will the inclusion of a picture in a PDF trigger the use of a conversion? Can't this be the cause for such a large target-PDF? – Keks Dose Dec 04 '14 at 11:21
  • @KeksDose You mean, that EPS files can be converted to PDF automatically? Usually PDF files are smaller because of the PDF compression. – Heiko Oberdiek Dec 04 '14 at 11:25
  • Well, the other way round: PDF is a kind of container. Maybe -- you know, I'm a silly user -- the picture inside the PDF is in a format which can not be used by pdftex and so pdftex converts the picture inside the PDF to something different before including it in the main file. And by converting the picture get bloated. I'm asking, because some other cases raised my suspicion that a convertation process might bloat the main PDF. If I'm completly wrong, please don't waste you time, just give a short notice. – Keks Dose Dec 04 '14 at 12:22
  • @KeksDose AFAIK, images inside a PDF are not converted to other formats, if the PDF is included as image by pdfTeX/LuaTeX. – Heiko Oberdiek Dec 04 '14 at 12:44
6

There is a wonderful script to shrink a PDF: https://github.com/pts/pdfsizeopt . I've been using it for years and can recommend it.

Regarding the question of the cause for such a large PDF: Maybe you saved different versions of your file, which only have a different file extension (*.jpg, *.png ...). For some reasen LuaLaTeX prefers the large JPG and not the small PNG.

Or -- we had that earlier -- a background process of LuaLaTeX converts your files to something different. Have a look into the log file, whether there is a hint for that? Otherwise provide an MWE and a picture.

A kind of last resort is to open the PDF in Acrobat Standard and let Acrobat shrink it. But you need the software...

Keks Dose
  • 30,892