Clone or import pages between PDF documents in C# and VB.NET

With GemBox.Pdf, you can clone or import pages between PDF documents in your C# or VB.NET application.

For more information about cloning in GemBox.Pdf, see Document Structure help page.

The following example demonstrates how to clone pages from another PDF document.

Screenshot
PDF Library for C# / VB.NET Screenshot

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download an input file

using System;
using System.IO;
using GemBox.Pdf;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        PdfDocument document = PdfDocument.Load("Invoice.pdf");

        int pageCount = 5;
        string pathToResources = "Resources";

        // Load a source document.
        using (PdfDocument source = PdfDocument.Load(Path.Combine(pathToResources, "Reading.pdf")))
        {
            // Get the number of pages to clone.
            int cloneCount = Math.Min(pageCount, source.Pages.Count);

            // Clone the requested number of pages from the source document
            // and add them to the destination document.
            for (int i = 0; i < cloneCount; i++)
                document.Pages.AddClone(source.Pages[i]);
        }

        document.Save("Cloning.pdf");
        document.Close();
    }
}
Imports System.IO
Imports GemBox.Pdf

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As PdfDocument = PdfDocument.Load("Invoice.pdf")

        Dim pageCount As Integer = 5
        Dim pathToResources As String = "Resources"

        ' Load a source document.
        Using source As PdfDocument = PdfDocument.Load(Path.Combine(pathToResources, "Reading.pdf"))
            ' Get the number of pages to clone.
            Dim cloneCount = Math.Min(pageCount, source.Pages.Count)

            ' Clone the requested number of pages from the source document 
            ' and add them to the destination document.
            For i As Integer = 0 To cloneCount - 1
                document.Pages.AddClone(source.Pages(i))
            Next
        End Using

        document.Save("Cloning.pdf")
        document.Close()

    End Sub

End Module