Adobe® PDF Library

Using the PDF Optimizer to Manage the Size of PDF Documents


View Sample Code

Use the PDFOptimizerSample to experiment with the PDF Optimization feature in the Adobe PDF Library. PDF Optimization allows you to compress a PDF document to make it smaller. Besides being easier to manage, an optimized PDF document tends to load faster when opened in a web browser. The PDF Optimizer in the Library is designed to work in a similar way as a feature in Adobe Acrobat that can save a PDF document to optimize that file, when selecting Save As.

Note that the Adobe PDF Library offers the PDF Optimizer for the C Language, Java, and Microsoft .NET interfaces, and a sample program is provided for the feature for each language as well:

  • PDFOptimizer.cpp
  • PDFOptimizerSample.cs

See Working with the PDF Optimizer.

This sample demonstrates using the Java interface to optimize an existing PDF file. The sample linearizes a sample document that you provide. A linearized PDF is restructured in a way that allows the first page of the file to appear on a user’s web browser while the rest of the file is being downloaded.

The program names a default PDF input document, and provides the name of an output file. You can enter the name of your own PDF input document in the program if you like, or add the name to a command prompt. The sample compares the size of the resulting file, in megabytes, to the size of the original, and then displays a message showing how much the file size was reduced. For example, if the original PDF document was 1.7 MB, and the output file is .93 MB, the program will show that the new output file is "53% the size of the original."