Merge PDF Files in .NET

It’s possible to use the Document Editor to merge multiple documents together to create one large document.

To do this, you can take one of the documents as a base for the Document Editor and insert the second:

// Insert the second document before the original and export to the temporary file.
var filepath = "documentEditorOutput.pdf";
var documentEditor = documentToEdit.GetDocumentEditor();
documentEditor.importDocument(0, DocumentEditor.IndexPosition.BeforeIndex, new FileDataProvider("secondDocument.pdf"));
documentEditor.SaveDocument(new FileDataProvider(filepath));

Chaining Edits Together

Document edits can be chained to perform multiple synchronous operations to create a single document. For example:

var filepath = "documentEditorOutput.pdf";
var documentEditor = documentToEdit.CreateDocumentEditor();
documentEditor.importDocument(0, DocumentEditor.IndexPosition.BeforeIndex, new FileDataProvider("secondDocument.pdf"));
documentEditor.KeepPages(new List<int> {0, 2});
documentEditor.ClearPageLabels();
documentEditor.SetPageLabel(new List<int> {0}, "Test");
documentEditor.SaveDocument(new FileDataProvider(filepath));