What does PDDocInsertPages do internally?
Estimated Reading Time: 1 MinutesPDDocInsertPages is a method that can be used to merge pages in multiple PDF documents into a single PDF. The process requires a number of steps and is memory intensive, but you can merge as many source PDF documents as your system memory will allow.
PDDocInsertPages completes these steps:
- Copies the page content stream from the source documents to the target document
- Copies the referenced non-font resources to the target document. Note that non-font resources can be stored separately from the source PDF as external files, but this is rare.
- Copies fonts that are not embedded in the source document into the target document
- Merges font subsets in the source documents for fonts that do exist in the target document
- Merges bookmark, page label, name and number trees between the source page and target document and rewrites the referenced items to their places in the new document
- Merges the structure tree elements, if any
- Copies annotations to the target document
You will find it much more efficient to issue a single call to PDDocInsertPages to insert 100 pages from a source document into a target document than if you call the method 100 times to insert one page at a time.
Open both documents using PDDocOpen(), and close both with PDDocClose(). Use PDDocSave() to save the PDF document that you added pages to.
Depending on the document structure, it may be beneficial to turn off the insert flags PDInsertBookmarks andPDInsertThreads. In addition, an application can disable font merging by adding the PDInsertDoNotMergeFonts flag (Datalogics release). This can improve performance when merging large numbers of pages, though it may result in larger output file sizes.
Look at the sample program provided with Adobe PDF Library, MergeDocuments.