Import pages from multiple PDF documents to one PDF document at specific page range using C# and VB.NET.
The Syncfusion Essential® PDF is a feature-rich and high-performance .NET PDF library that is 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. Using this library, you can import pages from multiple PDF documents to one PDF document at a specific page range using C# and VB.NET.
Steps to import pages from multiple PDF documents to one PDF document at specific page range programmatically
1. Create a new C# console application project.
2.
Install the Syncfusion.PDF.WinForms NuGet packages as a reference to your .NET Framework application from NuGet.org.
3. Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing;
VB.NET
Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Graphics Imports Syncfusion.Pdf.Parsing
4. The following code example shows how to import pages from multiple PDF documents to one PDF document at a specific page range using C#.
C#
//Load twelve pages PDF document PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument("../../Data/Brochure.pdf"); //Load three pages PDF document PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument("../../Data/Barcode.pdf"); //Create a new PDF document PdfDocument document = new PdfDocument(); //Import two pages from the first document document.ImportPageRange(loadedDocument1, 0, 1); //Import all pages from the second document. So, this will be the third page of the first document document.ImportPageRange(loadedDocument2, 0, loadedDocument2.Pages.Count - 1); //Import the remaining pages from the first document document.ImportPageRange(loadedDocument1, 2, loadedDocument1.Pages.Count - 1); //Save and closes the documents document.Save("Sample.pdf"); document.Close(true); Process.Start("Sample.pdf");
VB.NET
'Load twelve pages PDF document Dim loadedDocument1 As PdfLoadedDocument = New PdfLoadedDocument("../../Data/Brochure.pdf") 'Load three pages PDF document Dim loadedDocument2 As PdfLoadedDocument = New PdfLoadedDocument("../../Data/Barcode.pdf") 'Create a new PDF document Dim document As PdfDocument = New PdfDocument() 'Import two pages from the first document document.ImportPageRange(loadedDocument1, 0, 1) 'Import all pages from the second document. So, this will be the third page of the first document document.ImportPageRange(loadedDocument2, 0, loadedDocument2.Pages.Count - 1) 'Import remaining pages from the first document document.ImportPageRange(loadedDocument1, 2, loadedDocument1.Pages.Count - 1) 'Save and closes the documents document.Save("Sample.pdf") document.Close(True) Process.Start("Sample.pdf")
By executing the program, you will get the PDF document as follows.
A complete working sample can be downloaded from PdfSample.zip.
Take a moment to peruse the documentation for working with pages. You can find the options like inserting, rotating, importing, and rearranging the pages from an existing document, removing the pages, and splitting a PDF file to individual pages.
Refer to hereto explore a rich set of Syncfusion Essential® PDF features.
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without trail message.
See Also:
https://help.syncfusion.com/file-formats/pdf/working-with-pages
Conclusion
I hope you enjoyed learning about how to import pages from multiple PDF documents to one PDF document at specific page range using C# and VB.NET.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation 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!