How to merge PDF documents from ArrayList 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. Using this library, you can merge PDF documents from ArrayList using C# and VB.NET.
Steps to merge PDF documents from ArrayList using C# 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.Parsing;
VB.NET
Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Parsing
4. The following code example shows how to merge PDF documents from ArrayList using C#.
C#
// Get files from folder string[] filePaths = Directory.GetFiles("../../Data/"); // Create the array list ArrayList mergearray = new ArrayList(filePaths.Length); // Copy file path to the array list for (var i = 0; i <= filePaths.Count() - 1; i++) mergearray.Add(filePaths[i]); // Create a new PDF document PdfDocument finalDoc = new PdfDocument(); // Merge the PDF document for (int i = 0; i <= mergearray.Count - 1; i++) { // Load an existing PDF PdfLoadedDocument loadedDocument = new PdfLoadedDocument(mergearray[i].ToString()); // Merge the PDF documnet PdfDocument.Merge(finalDoc, loadedDocument); } // Save and close the PDF document finalDoc.Save("Sample.pdf"); finalDoc.Close(true); Process.Start("Sample.pdf");
VB.NET
'Get files from folder Dim filePaths As String() = Directory.GetFiles("../../Data/") 'Create the array list Dim mergearray As ArrayList = New ArrayList(filePaths.Length) 'Copy file path to the array list For i = 0 To filePaths.Count() - 1 mergearray.Add(filePaths(i)) Next 'Create a new PDF document Dim finalDoc As PdfDocument = New PdfDocument() 'Merge the PDF document For i As Integer = 0 To mergearray.Count - 1 'Load an existing PDF Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument(mergearray(i).ToString()) 'Merge the PDF documnet PdfDocument.Merge(finalDoc, loadedDocument) Next 'Save and Close the PDF document finalDoc.Save("Sample.pdf") finalDoc.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 to merge the multiple PDF documents with the string array and importing pages from multiple documents with Essential PDF. Also, brief details about split, delete, and rotate PDF pages are available with code examples.
Refer to here to explore a rich set of Syncfusion Essential® PDF features.
An online sample link to merge PDF documents.
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/merge-documents
https://www.syncfusion.com/kb/9146/how-to-merge-pdf-files-in-c-vb-net
I hope you enjoyed learning about how to merge PDF documents from ArrayList using C# and VB.NET.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example 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!