Splitting PDF files into separate pages or groups of pages is a common task in software development. This may be necessary for processing large documents, organizing content, or optimizing data management. In this article, we will look at how you can split PDF files into separate pages or groups of pages using C# and .NET.
To complete the task of splitting PDF files, we will need to perform the following steps:
Complete code
using System;
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;
using SautinSoft;
using SautinSoft.Pdf;
using SautinSoft.Pdf.Content;
using System.Linq;
using SautinSoft.Pdf.Facades;
namespace Sample
{
class Sample
{
/// <summary>
/// Split PDF files in C# and .NET.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/split-pdf-files.php
/// </remarks>
static void Main(string[] args)
{
// Before starting this example, please get a free 100-day trial key:
// https://sautinsoft.com/start-for-free/
// Apply the key here:
// PdfDocument.SetLicense("...");
// Split PDF document by pages.
// The each page will be saves as a separate PDF file: "Page 0.pdf", "Page 1.pdf" ...
// Can work with relative and absolute paths.
PdfSplitter.Split(@"..\..\..\005.pdf", PdfLoadOptions.Default, 0,
int.MaxValue, (pageInd) => $"Page {pageInd}.pdf");
// The last parameter is "Func" to generate the output file name.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(@"Page 0.pdf") { UseShellExecute = true });
}
}
}
Imports System
Imports System.IO
Imports System.IO.Compression
Imports System.Collections.Generic
Imports SautinSoft
Imports SautinSoft.Pdf
Imports SautinSoft.Pdf.Content
Imports System.Linq
Imports SautinSoft.Pdf.Facades
Namespace Sample
Friend Class Sample
''' <summary>
''' Split PDF files in C# and .NET.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/split-pdf-files.php
''' </remarks>
Shared Sub Main(ByVal args() As String)
' Before starting this example, please get a free license:
' https://sautinsoft.com/start-for-free/
' Apply the key here:
' PdfDocument.SetLicense("...");
' Split PDF document by pages.
' The each page will be saves as a separate PDF file: "Page 0.pdf", "Page 1.pdf" ...
' Can work with relative and absolute paths.
PdfSplitter.Split("..\..\..\005.pdf", PdfLoadOptions.Default, 0, Integer.MaxValue, Function(pageInd) $"Page {pageInd}.pdf")
' The last parameter is "Func" to generate the output file name.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("Page 0.pdf") With {.UseShellExecute = True})
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: