This sample shows how to extract pages from one PDF document to another.

Use PdfDocument.ExtractPages method to extract pages to new document. Please note that ExtractPages method removes pages from the source document.

Extraction of pages from a single-paged document is forbidden.

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class ExtractPages
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            using (PdfDocument original = new PdfDocument())
            {
                for (int i = 0; i < 5; ++i)
                {
                    if (i != 0)
                        original.AddPage();

                    PdfPage page = original.Pages[i];
                    page.Canvas.DrawString("Page #" + (i + 1));
                }

                // extract first 3 pages. These pages will be removed from original PDF document.
                using (PdfDocument extracted = original.ExtractPages(0, 3))
                    extracted.Save("ExtractPages.pdf");

                Process.Start("ExtractPages.pdf");

                original.Save("ExtractPages_original.pdf");
            }

            Process.Start("ExtractPages_original.pdf");
        }
    }
}
VB
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class ExtractPages
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Using original As New PdfDocument()
                For i As Integer = 0 To 4
                    If i <> 0 Then
                        original.AddPage()
                    End If

                    Dim page As PdfPage = original.Pages(i)
                    page.Canvas.DrawString("Page #" + (i + 1).ToString())
                Next

                ' extract first 3 pages. These pages will be removed from original PDF document.
                Using extracted As PdfDocument = original.ExtractPages(0, 3)
                    extracted.Save("ExtractPages.pdf")
                End Using

                Process.Start("ExtractPages.pdf")

                original.Save("ExtractPages_original.pdf")
            End Using

            Process.Start("ExtractPages_original.pdf")
        End Sub
    End Class
End Namespace