Some test text!

menu
search
Save a documentkeyboard_arrow_down

Serialization

Serialization also known as saving provides the ability to write content back to a storage medium.

PDFTron SDK benefits include:

  • Incremental save (for fast save and document persistence)
  • Linearization (Fast Web View)
  • Supports compressed object streams
  • Unused object removal. This option can help you create smaller files
  • Serialize a document to memory, stream, or a file on disk

linkSave a document

To save a PDF document.

PDFDoc doc(filename);

// save the document to the filesystem
doc.Save(output_filename, SDFDoc::e_linearized, NULL);

// optionally save the document to a memory buffer
const char* buf = 0; 
size_t buf_sz;
doc.Save(buf, buf_sz, SDFDoc::e_linearized, NULL);

Read & write a PDF file from/to memory buffer
Full source code which illustrates how to read/write a PDF document from/to memory buffer. This is useful for applications that work with dynamic PDF documents that don't need to be saved/read from a disk.

linkAbout saving a document

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 MemoryFilter or HTTPFilter.

To save a PDF document to a file on disk, invoke its Save() method:

doc.save("out.pdf", SDFDoc::e_linearized, NULL);

The second argument is a bitwise disjunction of flags used as options during serialization.

PDFTron SDK 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. PDFTron SDK 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 e_incremental flag:

doc.save("out.pdf", SDFDoc::e_incremental, NULL);

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 e_remove_unused flag:

doc.save("out.pdf", SDFDoc::e_remove_unused, NULL);

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:

const char* buf = 0; 
size_t buf_sz;
doc.Save(buf, buf_sz, Doc::e_linearized, NULL);

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close