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 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 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 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 Leadtools.PdfCompressor.PdfCompressorEngine.Write(System.String) methods, use the Leadtools.PdfCompressor.PdfCompressorEngine.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 in 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:
After all data has been written to the file in memory, the file in memory should be written to a file on disk using Leadtools.PdfCompressor.PdfCompressorEngine.Write(System.String). Once the file has been written to disk somewhere, the user must free the PDF document handle and all associated memory by calling PdfCompressorEngine.Dispose. Please 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 functionality.