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

With PDF .Net, you can clone or import pages (and even page trees) between PDF documents in your C# or VB.NET application.

You can clone the entire PDF .Net, using the PDF .Net.Clone() method, or just specific pages using the PdfPages.AddClone()method. For more information about cloning in .Net, see the Document Structure help page.

The following example shows how to clone a page from another PDF document.

Complete code

using System;
using System.IO;
using SautinSoft;
using SautinSoft.Pdf;
using SautinSoft.Pdf.Content;

namespace Sample
{
    class Sample
    {
        /// <summary>
        /// Clone or import pages between PDF documents.
        /// </summary>
        /// <remarks>
        /// Details: http://sautinsoft/products/pdf/help/net/developer-guide/clone-or-import-pages.php
        /// </remarks>
        static void Main(string[] args)
        {
            string invoice = Path.GetFullPath(@"..\..\..\invoice.pdf"); 
            string pdffile = Path.GetFullPath(@"..\..\..\simple text.pdf");

            using (var document = PdfDocument.Load(invoice))
            {
                int pageCount = 5;

                // Load a source document.
                using (var source = PdfDocument.Load(pdffile))
                {
                    // 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");
            }
        }
    }
}

Download


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.