How to split a PDF into multiple files using C# and VB.Net

How to split a PDF into multiple files
using C# and VB.Net.



Complete code

using System;
using System.IO;
using System.Collections;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Split a PDF document by pages.
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();
            DirectoryInfo outDir = new DirectoryInfo(@"Pages");
            if (!outDir.Exists)
                outDir.Create();

            //v.Serial = "XXXXXXXXXXXXXXX";

            int ret = v.SplitPDFFileToPDFFolder(@"..\..\simple text.pdf", outDir.FullName);

            // 0 - split successfully.
            // 1 - error, can't open input file.
            // 2 - error, output directory doesn't exist.

            if (ret == 0)
            {
                System.Console.WriteLine("Split successfully!");
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outDir.FullName) { UseShellExecute = true });
            }
        }
    }
}

Download.

        
            Imports System
Imports System.IO
Imports System.Collections

Namespace Sample
	Friend Class Test

		Shared Sub Main(ByVal args() As String)
			' Split a PDF document by pages.
			Dim v As New SautinSoft.PdfVision()
			Dim outDir As New DirectoryInfo("Pages")
			If Not outDir.Exists Then
				outDir.Create()
			End If

			'v.Serial = "XXXXXXXXXXXXXXX"

			Dim ret As Integer = v.SplitPDFFileToPDFFolder("..\..\simple text.pdf", outDir.FullName)

			' 0 - split successfully.
			' 1 - error, can't open input file.
			' 2 - error, output directory doesn't exist.

			If ret = 0 Then
				System.Console.WriteLine("Split successfully!")
				System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outDir.FullName) With {.UseShellExecute = True})
			End If
		End Sub
	End Class
End Namespace

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.