How to merge PDF documents with grouped bookmarks in C# and VB.NET ?
The Syncfusion Essential PDF is a feature-rich and high performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, forms, compress, and secure PDF files.
This sample uses the following PDF documents and explains how to merge them with grouped bookmarks using Syncfusion .NET PDF library.
Steps to merge PDF documents with grouped bookmarks programmatically in C#:
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from the NuGet.org.
- You can merge two PDF documents by using the Merge method of PdfDocumentBase class.
C#
//Merge PDF file PdfDocumentBase.Merge(document, loadedDocument);
VB.NET
'Merge PDF file PdfDocumentBase.Merge(document, loadedDocument)
- Include the following namespaces in Program.cs file.
C#
using Syncfusion.Pdf;
VB.NET
Imports Syncfusion.Pdf
- Include the following code snippet in main method of Program.cs file to merge PDF documents with grouped bookmarks.
C#
//Create a new PDF document PdfDocument finalDoc = new PdfDocument(); //Create a string array of source files to be merged string[] source = { "Document1.pdf", "Document2.pdf" }; //Merge the PDF documents PdfDocument.Merge(finalDoc, source); //Save the PDF document finalDoc.Save("MergedDocument.pdf"); //Close the instance of PdfDocument finalDoc.Close(true);
VB.NET
'Create a new PDF document Dim finalDoc As PdfDocument = New PdfDocument 'Create a string array of source files to be merged Dim source() As String = {"Document1.pdf", "Document2.pdf"} 'Merge the PDF documents PdfDocument.Merge(finalDoc, source) 'Save the PDF document finalDoc.Save("MergedDocument.pdf") 'Close the instance of PdfDocument finalDoc.Close(True)
A complete work sample to merge PDF documents with grouped bookmarks can be downloaded from MergePDF.zip.
By executing the program, you will get the PDF document as follows.
Take a moment to peruse the documentation, where you will find other options like RTF to PDF conversion, XPS to PDF conversion, PDF to image conversion, HTML to MHTML, HTML to SVG, partial webpage to SVG, and more.
Click here to explore the rich set of Syncfusion Essential PDF features.
An online sample link to convert Word document to PDF, RTF to PDF, XPS to PDF, TIFF to PDF, PDF to Image, and Excel document to PDF.
See Also:
Merge all PDF files in a folder into single PDF document
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
I hope you enjoyed learning about how to merge PDF documents with grouped bookmarks in WinForms.
You can refer to our WinForms FileFormat Libraries to know about its other groundbreaking feature representations and how to quickly get started for configuration specifications. You can also explore our demo to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!