Many PDFs are designed for high-quality print output and are not optimized for the web. PDF files are based on PostScript and contain binary data. PDFs use LZW, JPEG, Flate (ZIP), CCITT (the facsimile standard, Group 3 or 4), run-length, and JBIG2 compression (in PDF version 1.4). The last four are used for monochrome images. Like other multimedia formats, optimizing PDFs takes a two-step approach: creating the compound document, and saving it.
The main factors that increase the size of PDFs are image resolution, image type (bitmapped or vector), and PDF version. To create the smallest possible PDFs for the web, minimize the number embedded images and fonts, substitute vector-based graphics where possible, and capture and prepare the images you include for maximum compressibility. See Chapter 12, "Optimizing Web Graphics," for more information on preparing compressible images.
For graphics that must be inserted as bitmapped images, use the best-quality images that you can at the output resolution of the PDF. This way, Acrobat Distiller compresses them only once, rather than resampling and recompressing images. Inserting compressed JPEGs within PDFs and recompressing them in Distiller can create noticeable artifacts.
Use vector-based graphics when possible for images that you would make into GIFs. Vector images are compact, scale perfectly , and look great at any resolution, even when printed. You also can compress vector image data in your PDF using ZIP compression, which is built into the PDF format. Acrobat Reader version 4 and higher also supports SVG.
Minimize the number of fonts that you use in your PDFs, or use one of the 14 built-in "base" fonts for maximum download speed.
You can create PDFs on the fly in a number of ways. Both open source and commercial products are available. For XML source files, you can use the Formatting Objects Processor (FOP) from Apache (http://xml.apache.org/fop/). FOP generates PDFs page by page, so it does basic page optimization and supports PDF version 1.3 (Acrobat 4). Another open source tool in Java is iText (http://www.lowagie.com/iText/); this tool con verts XML directly into PDF documents and compresses for size but does not linearize.
Many commercial products including PDFLib (www. pdflib .com) enable you to create PDF documents on many platforms, including Windows with ASP and ASP.NET.
In Acrobat (the full version) or Distiller, you can reduce the resolution of bitmapped images to a fixed value and use JPEG or ZIP compression. Set the resolution to "screen" (72 dpi) to create the smallest files or "eBook" (150 to 300 dpi) for laptops and mobile devices (see Figure 13.10).
Adobe recommends using the default of eBook over the screen option, although eBook files are larger. Double-check your images for legibility after using the screen setting because they can become blurry. Table 13.2 compares various Distiller settings on a sample file with a number of images:
|Image resolution||N/A||72 dpi||150 to 300 dpi||300 to 1200 dpi||2400 dpi|
The text itself also can be compressed using ZIP compression in Distiller. Always subset your embedded fonts for the web. Font subsets contain only the glyph descriptions that are actually used in your document. If you don't subset your fonts, the entire font will be included in the PDF document, which can easily add 40KB per font to the file.
To minimize file size, turn off thumbnails when saving PDFs for the web.
For PDF files, the higher the version the smaller the file. Adobe has made Acrobat more efficient with each revision. Of course, using the latest PDF version will create compact files but require that your users have the latest plug-in.
Even after you've created your PDF, you must optimize the file for the web. Optimizing PDF documents does the following:
Removes duplicate objects
Removes old and unneeded versions of objects
Linearizes the output per page
The result is a compact, linearized PDF that displays the first page (or an arbitrary page) quickly, while the rest of the file downloads. Although linearized PDFs are slightly larger, they also increase perceived speed.
One easy way to trim your PDF file is to Save As to a new file in Acrobat. This removes unnecessary objects automatically. Finally, use the Acrobat's PDF Consultant (select Tools > PDF Consultant) to analyze and remove elements, and select "Optimize Space"(select Tools > PDF Consultant > Optimize Space) to minimize file size.
For more information about PDF optimization, see these resources: