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 PDF document by pages.
SautinSoft.PdfVision v = new SautinSoft.PdfVision();
string inpFile = @"..\..\simple text.pdf";
DirectoryInfo outFolder = new DirectoryInfo(@"Pages");
if (!outFolder.Exists)
outFolder.Create();
//v.Serial = "XXXXXXXXXXXXXXX";
int ret = v.SplitPDFFileToPDFFolder(inpFile, outFolder.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!");
// Open the resulting folder with the PDF pages.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFolder.FullName) { UseShellExecute = true });
}
}
}
}
Imports System
Imports System.IO
Imports System.Collections
Namespace Sample
Friend Class Test
Shared Sub Main(ByVal args() As String)
' Split PDF document by pages.
Dim v As New SautinSoft.PdfVision()
Dim inpFile As String = "..\..\simple text.pdf"
Dim outFolder As New DirectoryInfo("Pages")
If Not outFolder.Exists Then
outFolder.Create()
End If
'v.Serial = "XXXXXXXXXXXXXXX"
Dim ret As Integer = v.SplitPDFFileToPDFFolder(inpFile, outFolder.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!")
' Open the resulting folder with the PDF pages.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFolder.FullName) With {.UseShellExecute = True})
End If
End Sub
End Class
End Namespace
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: