PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.

Split PDF pages in C# and VB.NET

The following code sample shows how to split PDF pages in C# and VB.NET.

Splitting PDF pages is quite similar to append PDF pages. The only difference is that appending copy pages from PDF documents onto another existing PDF document, while splitting copy pages onto a new PDF document. The following sample code shows how to split a PDF document with multiple pages into several PDF documents each containing a single page.

How to split pdf in C# / VB.NET

using ( FileStream inFile = new FileStream( @"..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read ) )
{
    // open the source document
    Document documentIn = new Document( inFile );

    // enumerate the pages in the source document
    for ( int i=0; i<documentIn.Pages.Count; i++ )
    {
        // create the target document
        Document documentOut = new Document();

        // append page i to the target document, we don't want to change the documentIn, so Clone the page.
        documentOut.Pages.Add( documentIn.Pages[i].Clone() );

        // write the target document to disk
        using ( FileStream outFile = new FileStream( 
                    string.Format( @"..\..\split_{0}.pdf", i ), 
                    FileMode.Create, FileAccess.Write ) )
        {
            documentOut.Write( outFile );
        }
    }
}
Using inFile As New FileStream("..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)
    ' open the source document
    Dim documentIn As New Document(inFile)
    For i As Integer = 0 To documentIn.Pages.Count - 1

        ' enumerate the pages in the source document
        ' create the target document
        Dim documentOut As New Document()

        ' append page i to the target document, we don't want to change the documentIn, so Clone the page.
        documentOut.Pages.Add(documentIn.Pages(i).Clone())

        ' write the target document to disk
        Using outFile As New FileStream(String.Format("..\..\split_{0}.pdf", i), FileMode.Create, FileAccess.Write)
            documentOut.Write(outFile)
        End Using
    Next
End Using
Download PDFKit.NET 5.0
We will send you a download link

  • This field is for validation purposes and should be left unchanged.
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link.