Divide Multiple PDFs in C# and .NET

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:

  1. Add SautinSoft.PDF from NuGet.
  2. Split the PDF document into pages.
  3. Save each page as a separate PDF file.

Output result:

Following the above code example, developers can easily integrate PDF separation functionality into their applications, ensuring efficient document processing.

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 });
        }
    }
}

Download

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

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.