PDF Optimization – How to Create Small PDF Files Optimized for the Internet

file sizefontsonlinepdf

I feel that PDF documents when intended to be uploaded on the Internet should be of minimal final size in bytes. Many strategies exist to create such small documents:

  1. Pay attention to the size of the embedded raster images.

  2. Create diagrams with tikz or pstricks and avoid external applications that can create unwanted big files. Using tikz or pstricks provides access to an almost unlimited control of the properties of a specific object. For instance, creating a point A of coordinates (1,1) should be preferred to a point A of coordinates (1.0000000,1.00000000), that you cannot control in many applications.

  3. Pay attention to the fonts used in your documents. Some fonts contain a coding for a single size and are then scaled, when used in titles or equivalents. Some other fonts contain a coding for different size, making the document a bit larger. You may observe a non negligible difference.

I am interested in this 3rd point: have some of you investigated the best fonts for smaller PDF files?

Edit Compress.SmallPDF sounds like a good online solution to efficiently compress pdf files for free.

Best Answer

There are a number of tricks for getting optimized pdfs. Many of them are implemented in the tool pdfsizeopt. With some patches (posted in the pdfsizeopt bugtracker) this tool can run on all my tex-generated pdfs (and nearly all of the non-tex-generated ones). I use the commandline:

python ./pdfsizeopt.py --use-pngout=true --use-jbig2=true --use-multivalent=true --do-unify-fonts=false filetocompress.pdf

I use --do-unify-fonts=false even though it produces slightly larger pdfs, because of a bug where a few glyphs are not displayed with certain pdf viewers (windows adobe reader, for example).

There are indeed various things you can do during document production with tex, to make sure that the compressed pdf ends up as small as possible: several of these are discussed in the EuroTeX 2009 White paper about pdfsizeopt (available at https://github.com/pts/pdfsizeopt/releases/download/docs-v1/pts_pdfsizeopt2009.psom.pdf).

As regards fonts, pdfsizeopt will recode fonts to the very compressed CFF format, and take care of subsetting and duplication issues. I haven't investigated deeply, but in my tests it seems that of the 2 options for type 1 encoded T1 (multilingual) tex fonts, the Latin Modern fonts generally produce significantly larger PDFs than the CM-Super version (which is unfortunate, because Latin Modern is superior in just about every other way (see this question). I just did a quick experiment and this difference in size seems to be only for the pre-pdfsizeopt pdfs: after pdfsizeopt, Latin Modern is the same or smaller than CM-Super.

Using fonts that don't have optical scaling will indeed produce a smaller PDF, but I don't recommend it because if you are using multiple sizes then the non-optically scaled fonts will look much worse.