Xojo Conferences

DynaPDF Manual - Page 531

Previous Page 530   Index   Next Page 532

Function Reference
Page 531 of 766
The function rebuilds the content streams of all pages, templates, annotations, and form fields.
Useless operators as well as errors in content streams will be fully removed. The resulting content
streams are error free and usually smaller. How much the optimization takes effect depends on the
quality of the original content streams.
Besides content optimization it is also possible to flatten layers, scale or just re-compress images, or
to correct hairlines.
The parameter Flags is a bit mask. Multiple flags can be combined with a binary or operator, e.g.
ofInMemory | ofScaleImage.
The flag ofScaleImages will be ignored if the parameter Parms is set to NULL.
Optimize() does not rebuild font subsets like CheckConformance(). The function is part of DynaPDF
It is assumed that this function is called right before closing the PDF file. It is not allowed to call the
function twice for the same PDF file in memory.
After Optimize() was executed, close the file with CloseFile(), CloseFileEx(), or CloseAndSignFile()
for example.
If the flag ofInMemory is absent, then pages are directly written to the output file after optimization
to reduce the memory usage. If the PDF file was created in memory (this is the case if no ouput file
name was passed to CreateNewPDF()) then the output file must be opened with OpenOutputFile()
or OpenOutputFileEncrypted() beforehand. Note that it is not possible to sign the PDF file if the flag
ofInMemory is absent.
If the file should be signed too, then import the resulting PDF file again and sign it with
CloseAndSignFile() or CloseAndSignFileEx() for example.
Re-compressing 1 bit images with JBIG2
If the flag ofCompressWithJBIG2 is set, 1 bit images will be re-compressed with JBIG2 (if the image
was not already compressed with this filter). This can drastically reduce the file size since JBIG2
compression achieves much higher compression rates than any other 1 bit image filter that PDF
supports. The JBIG2 compression filter in DynaPDF is lossless, that means the original image quality
will be preserved.
Converting gray images to 1 bit (black & white)
Gray images will be converted to 1 bit b&w if the flag ofConvertGrayTo1Bit is set. The flag is
considered only if the flag ofCompressWithJBIG2 is set or if the parameter Parms and the flag
ofScaleImages is set. The conversion of gray images to b&w is mainly useful for scanned faxes since
many scanners create gray images for b&w input.

Previous topic: Optimize

Next topic: Possible issues