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.

public static PdfDocumentBase MergeFiles(string[] InputFiles)


  • 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:

using Spire.Pdf;
using System;

namespace MergePDFFiles
    class Program
        static void Main(string[] args)
            String[] files = new String[] { "Sample1.pdf", "Sample2.pdf", "Sample3.pdf" };
            string outputFile = "result.pdf";
            PdfDocumentBase doc = PdfDocument.MergeFiles(files);
            doc.Save(outputFile, FileFormat.PDF);
Imports Spire.Pdf

Namespace MergePDFFiles
	Class Program
		Private Shared Sub Main(args As String())
			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)
		End Sub
	End Class
End Namespace

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: