Simply Split PDF Document to Multiple Files in C#/VB.NET

This section will show you a very simple solution to split PDF file to multiple files in your .NET applications. The whole solution only requires four lines of key code for you to successfully split PDF document by pages via a .NET PDF component Spire.PDF for .NET.

Spire.PDF for .NET, built from scratch in C#, is a .NET PDF component that enables you to create, read, write and manipulate PDF documents without Adobe Acrobat or any other external libraries. Using Spire.PDF for .NET, you can view the main method, please preview the effective screenshot first:

Split PDF Document

The following is a list of two methods which have to be invoked during PDF splitting process:

doc.Split(pattern): After loading your PDF file or creating and editing a new PDF file, it is very easy for you to split the original PDF document by pages. Only one parameter is passed to offer a template name of the target PDF files.

String.Format(pattern, doc.Pages.Count - 1): By using the "string format" method, you can preview an existing file by returning the PDF file name which you want to process. The second parameter in this method is designed to point out the index item which begins with 0.

Spire.PDF for .NET helps you to easily accomplish your PDF split task by two methods, four lines of core code. Please download Spire.PDF for .NET and follow code below:

Code Sample for Splitting PDF in C# and VB.NET

using Spire.Pdf;

namespace split_pdf
    class Program
        static void Main(string[] args)
            //open an existing pdf document
            PdfDocument doc = new PdfDocument(@"..\Sample3.pdf");
            //Split one PDF document to multiple files
            String pattern = "SplitDocument-{0}.pdf";
            String lastPageFileName
                = String.Format(pattern, doc.Pages.Count - 1);
Imports Spire.Pdf

Namespace split_pdf
    Class Program
	Private Shared Sub Main(args As String())
		'open an existing pdf document
		Dim doc As New PdfDocument("..\Sample3.pdf")
		'Split one PDF document to multiple files
		Dim pattern As [String] = "SplitDocument-{0}.pdf"
		Dim lastPageFileName As [String] = [String].Format(pattern, doc.Pages.Count - 1)
	End Sub
    End Class
End Namespace