Creating a Compressed PDF File

LEADTOOLS PDF support includes 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 PdfCompressorEngine 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 can insert data to that new file.

There are two methods that can be used to insert an image into a PDF file. Use the PdfCompressorEngine.Insert(rasterimage) 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 PdfCompressorEngine.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 PdfCompressorOptions.ImageQuality and PdfCompressorOptions.OutputQuality members of the PdfCompressorOptions structure.

To work with MRC-segmented data that is inserted or saved using the PdfCompressorEngine.Insert(rasterimage,pdfcompressoroptions) and Write methods, use the SegmentImage event.

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

The PdfCompressorEngine.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 PdfCompressorEngine.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 PdfCompressorEngine.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, free the PDF document handle and all associated memory by calling PdfCompressorEngine.Dispose. Note that if PdfCompressorEngine.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.

Help Version 19.0.2017.10.19
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document