Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
Creating a Compressed PDF File

The PDF Plug-in also provides support for the PDF Compressor. Through MRC segmentation, this compressor can be used to break down a page/image into smaller segments, saving each segment using compression appropriate for that segment. Thus, one page of a PDF file may have an image JPEG compressed, some text JBIG2 compressed, and another area CCITT compressed. This whole process works to provide a PDF file with better compression and better quality than just a standard Raster PDF file.

The PDF Compressor is initialized by using the PdfCompressor constructor. In addition to initializing the compressor, this function also creates an empty PDF file in memory and provides a handle to this new file. With a new PDF file created, the user may insert data to that new file.

There are two methods that can be used to insert an image into a PDF file. Use the PdfCompressor.Insert (IRasterImage) method to compress the specified image without segmenting it, and insert it into the PDF file. To insert data in the new PDF file that is MRC segmented, call PdfCompressor.Insert(RasterImage, PdfCompressorOptions). This method will use MRC segmentation to segment the data, and will compress each segment using the most suitable compression, based on the input and output profiles. Those profiles are provided in the ImageQuality and OutputQuality members of the PdfCompressorOptions structure.

To work with MRC segmented data that is inserted or saved using the Insert and Write methods, use the SegmentImage event.

To insert data that is not MRC segmented in the new PDF file, call Insert. This method compresses the input image as one image and inserts it in the PDF file in memory.

The InsertSegments method applies a specified set of segments to an image, then compresses and inserts the resulting image into the PDF file in memory.

Set the compression type to be used with each image segment inserted in the PDF file by calling the SetCompression method. This method must be called before inserting the compressed image into the PDF file by calling the following methods:

If you do not call SetCompression before using the above methods, then the insertion process will use the default compression types.

After all data has been written to the file in memory, the file in memory should be written to a file on disk using Write. Once the file has been written to disk somewhere, the user must free the PDF document handle and all associated memory by calling Dispose. Please note that if Dispose is called before the file in memory has been written to a file on disk, the PDF file in memory will be destroyed and all the data in that file will be lost. This method should be the last method to be called when using the PDF compressor functionality.