Merging Documents
- 2 minutes to read
The PDF Document API component allows you to merge multiple PDF documents.
Before merging, create a document with no pages.
To create this document, create a PdfDocumentProcessor object instance and call the overloaded PdfDocumentProcessor.CreateEmptyDocument method (for example, via a file path).
This method saves the merge result on a local disk to decrease memory consumption when merging documents. This means the document’s content is not kept in memory during the merging.
Note
The PDF Document API component retains the original document’s content while merging documents.
To add a required document to the resulting document, call an overloaded PdfDocumentProcessor.AppendDocument method.
When the merge is completed, close the resulting document by disposing of the PdfDocumentProcessor instance.
Note that you do not need to save this document since it is written during the merging.
Example
This example illustrates how to use the PDF Document API component for merging pages of two separate PDF documents into a single PDF document.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-merge-documents-into-a-single-pdf-t114298
Imports DevExpress.Pdf
Namespace PdfMergeExample
Friend Class Program
Shared Sub Main(ByVal args() As String)
Using pdfDocumentProcessor As New PdfDocumentProcessor()
pdfDocumentProcessor.CreateEmptyDocument("..\..\docs\Merged.pdf")
pdfDocumentProcessor.AppendDocument("..\..\docs\TextMerge1.pdf")
pdfDocumentProcessor.AppendDocument("..\..\docs\TextMerge2.pdf")
End Using
End Sub
End Class
End Namespace