-
Notifications
You must be signed in to change notification settings - Fork 217
Compression
By default, the PDF Library compresses all streams with Flate compression using zlib.
This is true except for TIFF Images that are compressed as CCIT, in which case they remain with this compression, to save the decoding-encoding time.
It is possible to control two aspects of the compression. one – whether compression takes place, two – what kind of compression.
You can control whether streams are compressed or not with the PDFWriter object.
when Initializing the PDFWriter object you use the following method:
EStatusCode StartPDF(const string& inOutputFilePath,
EPDFVersion inPDFVersion,
const LogConfiguration& inLogConfiguration,
const PDFCreationSettings& inPDFCreationSettings);
The 4th parameter is of type PDFCreationSettings (found in the header of PDFWriter), which has a single boolean member named CompressStreams. This member determines whether streams are compressed or not. For example:
PDFWriter pdfWriter;
pdfWriter.StartPDF("c:\\test.pdf",ePDFVersion13,
LogConfiguration::DefaultLogConfiguration,
PDFCreationSettings(false));
The above code will shut down compression, note how PDFCreationSettings is created with false value in the constructor, to indicate that compression is not to happen.
It is possible to replace the compression mechanism. To do that you have to create an object that implements IByteWriter interface, which is the base for all Output streams. read about output stream in IO.
The new implementation, which you will provide, will be a stream object that is able to write compressed buffers to another stream. This way, the library will be able to provide the object the file stream to write to, and the implemented stream will only have to cover the compression itself.
Apart from implementing IByteWriter, you will also have to create an extender object for the ObjectsContext.
And Extender object for the ObjectsContext object implements IObjectsContextExtender.
You can read more about the methods of the extender in the “Extensibility” section in the help on the ObjectsContext here – The ObjectsContext object.
The extender implementation simply enables hooking between the new compression stream implementation and the actual stream that is being written to.
Therefore the only part that remains is to show how to set the extender object on the ObjectsContext. easy. check the following block:
IObjectsContextExtender* myObjectsExtender = new MyObjectsExtender();
pdfWriter.GetObjectsContext().SetObjectsContextExtender(myObjectsExtender);
The first line creates a new extender of the class MyObjectsExtender, which implements the IObjectsContextExtender interface. it then gets the ObjectsContext from the pdf writer object, and sets the extender on it using the SetObjectsContextExtender function.
- First Steps In Creating a PDF file
- Creating PDF Pages
- Images Support
- Text Support
- Adding Content to PDF Pages
- Links
- Unicode and UnicodeString class
- PDF Embedding
- Custom input and output
- Using Form XObjects
- Forward Referencing
- JPG Images Support
- TIFF Images Support
- PNG Images support