How to Import Multiple PDF Pages to One in C# and VB.NET in .NET PDF?
The Syncfusion Essential® .NET PDF library is a feature-rich and high-performance library that is used to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, work with forms, compress, and secure PDF files. Using this library, you can import pages from multiple PDF documents into one PDF document at a specific page range using C# and VB.NET.
Steps to import pages from multiple PDF documents into one PDF document at a specific page range programmatically:
1. Create a new C# console application project.
2.
Install the Syncfusion.PDF.WinForms NuGet package 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 into one PDF document at a specific page range using C#.
C#
// Load twelve-page PDF document
PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument("../../Data/Brochure.pdf");
// Load three-page 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. 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 close the documents
document.Save("Sample.pdf");
document.Close(true);
Process.Start("Sample.pdf");
VB.NET
' Load twelve-page PDF document
Dim loadedDocument1 As PdfLoadedDocument = New PdfLoadedDocument("../../Data/Brochure.pdf")
' Load three-page 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. 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 close 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 options like inserting, rotating, importing, and rearranging pages from an existing document, removing pages, and splitting a PDF file into 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 a trial message.
See Also:
https://help.syncfusion.com/file-formats/pdf/working-with-pages
Conclusion
I hope you enjoyed learning about how to import multiple Pdf Pages to one in C# and VB.NET in .NET PDF.
You can refer to our .Net Pdf feature tour page to learn about its other groundbreaking feature representations. You can also explore our 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 support forums 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 or feedback portal. We are always happy to assist you!