ImageGear improves the overall size of saved PDF documents by reducing or removing data structures in a PDF document.
File size improvements will vary with each PDF file. In some cases, file size reduction is dramatic. By default, ImageGear removes standard fonts embedded in a PDF document for additional compression benefits. Re-saving an optimized PDF file is not expected to further reduce its size. Less frequently, PDF file size may increase due to metadata that is always written when PDF documents are saved.
WARNING: Saving compressed may invalidate PDF/A and PDF/X compliant documents. Refer to API reference topic
ImGearPDFDocument.
SaveCompressed() for additional details.
To compress a PDF document using ImageGear:
- Read the PDF document into a System.IO.Stream object.
- Read the stream using ImGearFileFormats.LoadDocument, casting the ImGearDocument object returned to an ImGearPDFDocument object.
- Save the PDF to disk or memory using the ImGearPDFDocument.SaveCompressed() method.
If compressing a file would result in an increased file size, the original file is saved instead.
The following is a sample method that illustrates how to re-compress a PDF file to memory:
PDF support needs to be initialized first for this snippet to work. To get familiar with initializing IGNET, initializing PDF support, loading a PDF, saving a PDF, and terminating PDF support, try any one of the
tutorials.
Refer to the sample SaveCompressedPDF for a more complete example of re-saving PDF files (see PDF Samples).
Compression Controlling Options
ImageGear provides below options to control compression:
Downsample High-Resolution Images
Downsampling replaces higher resolution images with lower resolution equivalents when visual quality is not too severely reduced. The process of downsampling will reduce the number of pixels in an image.
This option is enabled by default.
If the PDF is intended to be viewed at large magnification values, then disable this option:
Re-compress Bitonal Images
Re-compress Bitonal Images to JBIG2: Lossless Generic
Use JBIG2 lossless generic compression when the content of the image is unknown.
Re-compress Bitonal Images to JBIG2: Lossless Text
Use JBIG2 lossless text compression when the content of the image is known to contain text or symbols, since it can provide greater compression than JBIG2 lossless generic.
Re-compress Bitonal Images to JBIG2: Lossy Text
Use JBIG2 lossy text compression when the content of the image is known to contain only text or symbols, since it can provide even greater compression than JBIG2 lossless text with low risk of introducing errors.
Re-compress Images with JPEG Compression
ImGearCompressOptions uses JPEG compression by default. The compression level can be controlled (or disabled) by setting RecompressImageJpegCompressionLevel to one of the following five values: None, LossyLow, LossyMedium, LossyHigh, LossyMaximum.
Re-compress Images with JPEG2000 Compression
JPEG2000 compression must be enabled by setting the RecompressUsingJpeg2K property to true. The compression level can be controlled by setting RecompressImageJpeg2kCompressionLevel to one of the following five values: Lossless, LossyMinimum, LossyLow, LossyMedium, LossyHigh, LossyMaximum.
Remove Metadata
When enabled, all metadata streams, except for the document's main metadata stream located in the catalog dictionary, are removed.
This option is disabled by default.
Remove Image Thumbnails
When enabled, image thumbnails are removed from all pages of the document.
This option is disabled by default.