Creating a Compressed PDF File

PDF support includes 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, Jpeg2000 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 calling LPDFCompressor::Init. In addition to initializing the compressor, this function also creates an empty PDF file in memory. With a new PDF file created, the user may insert data to that new file. The user has the option of inserting material that has or has not been segmented using MRC Segmentation.

To insert data in the new PDF file that is MRC segmented, call LPDFCompressor::InsertMRC. This function will use MRC segmentation to segment the data, and will compress each segment using the most suitable compression, based on input and output profiles. Those profiles are provided in the imageQuality and outputQuality members of the PDFCOMPOPTIONS structure.

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

The user can also insert user-defined segments into a PDF file. This is done using the LPDFCompressor::InsertSegments function, which applies a specific set of segments to a bitmap, then compresses and inserts the resulting image into the PDF file in memory.

Any time MRC segmented data is inserted using LPDFCompressor::InsertMRC, or anytime an image is inserted by calling LPDFCompressor::InsertNormal, the LPDFCompressor::ImageCallback is called, if LBase::EnableCallBack was called previously with bEnable set to TRUE. This callback function allows the user to accept the insertion of the segment and continue to the next segment, or reject the insertion of the current segment and continue to the next segment. Within the LPDFCompressor::ImageCallBack function, the user should return SUCCESS to add the current segment and continue with the process, or FAILURE, to not add this segment and proceed with the next one.

Before inserting images or segments into a PDF file, the user should set the compression type. The LPDFCompressor::SetCompression function lets the user specify the type of compression to use for 1-bit, 2-bit and picture segments. This function must be called before inserting a compressed image into the PDF file using LPDFCompressor::InsertNormal, before inserting an MRC segment using LPDFCompressor::InsertMRC, or before inserting a user-defined segment using LPDFCompressor::InsertSegments. If the user does not call LPDFCompressor::SetCompression before using these functions, then the default compression types are used.

After all data has been written to the file in memory, the file in memory should be written to a file on disk using LPDFCompressor::Write. Once the file has been written to disk somewhere, the user must free all associated memory by calling LPDFCompressor::Free. Please note that if LPDFCompressor::Free 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 should be the last function called when working with the PDF compressor.

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS MRC C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.