Articles in this section
Category / Section

How to merge PDF documents from ArrayList using C# and VB.NET

2 mins read

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.

Create Console application

2. Install the Syncfusion.PDF.WinForms NuGet packages as a reference to your .NET Framework application from

Install NuGet packages

3. Include the following namespaces in the Program.cs file.


using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;



Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Parsing


4. The following code example shows how to merge PDF documents from ArrayList using 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++)
// 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 



'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
'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)
'Save and Close the PDF document 


By executing the program, you will get the PDF document as follows.

Output document

A complete working sample can be downloaded from

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 splitdelete, 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:

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied