PDF Merge in C#, VB.NET

  • Demo
  • C# source
  • VB.Net source

The sample demonstrates how to merge multiple PDF documents to one PDF document.

(NO screenshot)

using System;
using Spire.Pdf;

namespace MergeDocuments
    class Program
        static void Main(string[] args)
            //pdf document list
            String[] files = new String[]
            //open pdf documents            
            PdfDocument[] docs = new PdfDocument[files.Length];
            for (int i = 0; i < files.Length; i++)
                docs[i] = new PdfDocument(files[i]);

            //append document

            //import page
            for (int i = 0; i < docs[2].Pages.Count; i = i + 2)
                docs[0].InsertPage(docs[2], i);

            //Save pdf file.

            foreach (PdfDocument doc in docs)

            //Launching the Pdf file.

Imports Spire.Pdf

Namespace MergeDocuments
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'pdf document list
            Dim files() As String = {"Sample3.pdf", "Sample2.pdf", "Sample1.pdf"}
            'open pdf documents            
            Dim docs(files.Length - 1) As PdfDocument
            For i As Integer = 0 To files.Length - 1
                docs(i) = New PdfDocument(files(i))
            Next i

            'append document

            'import page
            For i As Integer = 0 To docs(2).Pages.Count - 1 Step 2
                docs(0).InsertPage(docs(2), i)
            Next i

            'Save pdf file.

            For Each doc As PdfDocument In docs
            Next doc

            'Launching the Pdf file.
        End Sub

    End Class
End Namespace