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 object is initialized by calling PDFCompInit method. In addition to initializing the compressor object, this method 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 PDFCompInsertMRC method. This method will use MRC segmentation to segment the data, and will compress each segment using the most suitable compression, based on PDF Compressor options. Those options are provided in the following properties:
In addition to initializing the PDF Compressor, the PDFCompInit method enables or disables firing the PDFCompEvent event. The PDFCompEvent event is fired anytime a segmented bitmap is inserted by calling the PDFCompInsertMRC method or anytime an image is inserted by calling the PDFCompInsertNormal method. The user must set the EnableAddSegment property within this event to approve or cancel the addition of a segment to the PDF file. Each time this event is fired, the MRCSegmentInfo property is updated.
To insert data that is not MRC segmented in the new PDF file, call the PDFCompInsertNormal method. This method compresses the input image as one image and inserts it in the PDF file in memory.
Before inserting images or segments into a PDF file, the user should set the compression type. The PDFCompSetCompression method lets the user specify the type of compression to use for 1-bit, 2-bit and picture segments. This method must be called before inserting a compressed image into the PDF file using the PDFCompInsertNormal method, or before inserting a segment using the PDFCompInsertMRC method. If the user does not call this method before using these methods, then the default compression types are used.
The user can insert user-defined segments into a PDF file. This is done by setting the UserSegmentInfoCount to the number of user defined segments to be added, setting the actual segment data in the UserSegmentInfo Property, and then calling the PDFCompInsertSegments method. The UserSegmentInfo property is a pointer to an ILTSegmentInfo object that contains the properties listed below. It is these properties that are set with the user-defined segment information.
After all data has been written to the file in memory, the file in memory should be written to a file on disk using the PDFCompWrite method. Once the file has been written to disk somewhere, the user must free all the memory allocated by the PDF compressor object by calling the PDFCompFree method. Please note that if PDFCompFree 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.