Merge PDF Files with New Method in C#

Using Spire.PDF, you can split or merge PDF files easily and conveniently.In this article, we will introduce you a new method to merge PDF files.

[C#]
public static PdfDocumentBase MergeFiles(string[] InputFiles)

Paremeters:

  • Inputfiles, an array stores the names of files to merge.
  • Return value, a PdfDocumentBase object containing merged documents.

The new method is easier and more practical than the old ones. And it can merge many files without considering the structure of the files.

Bellowing is complete code:

[C#]
String[] files = new String[] { "Sample1.pdf", "Sample2.pdf", "Sample3.pdf" };          
string outputFile = "result.pdf";
PdfDocumentBase doc = PdfDocument.MergeFiles(files);
doc.Save(outputFile, FileFormat.PDF);
[VB.NET]
Dim files As String() = New String() {"Sample1.pdf", "Sample2.pdf", "Sample3.pdf"}
Dim outputFile As String = "result.pdf"
Dim doc As PdfDocumentBase = PdfDocument.MergeFiles(files)
doc.Save(outputFile, FileFormat.PDF)

PS: To use PdfDocument.MergeFiles you will need to add reference System.Web.dll to your project. Otherwise, you will get an error.

Effect Screenshots:

merge_pdf_files

result_pdf