PDF document can be serialized (or saved) to a file on a disk, to a memory buffer, or to an arbitrary data stream such as
To save a PDF document to a file on disk, invoke its
The second argument is a bitwise disjunction of flags used as options during serialization.
PDFNet allows a document to be saved incrementally (see section 2.2.7 "Incremental Update" in the PDF Reference Manual). Because applications may allow users to modify PDF documents, users should not have to wait for the entire file (which can contain hundreds of pages) to be rewritten each time modifications to the document are saved. PDFNet allows modifications to be appended to a file, leaving the original data intact. The addendum appended when a file is incrementally updated contains only those objects that were actually added or modified. Incremental update allows an application to save modifications to a PDF document in an amount of time proportional to the size of the modification rather than the size of the file. In addition, because the original contents of the document are still present in the file, it is possible to undo saved changes by deleting one or more file updates.
Changes can be appended to an existing document using
Note that the file output name matches the input name.
Over time, PDF documents may accumulate unused objects like old updates, modifications, unused fonts, images, and so on. To trim down the file size by removing these unused objects, use the
In order to provide user feedback, the
PDFDoc.Save() method accepts objects which inherit from the ProgressMonitor class. ProgressMonitor provides a callback interface that keeps the client application up to date about the Save function's progress.
A PDF document can also be serialized into a memory buffer as follows:
byte buf = doc.Save(0);