1. Home
  2. /
  3. GroupDocs.Merger.LowCode
  4. /
  5. Developer Guide
  6. /
  7. Split PDF (SplitPdf)

Using SplitPdf to Split PDF Documents

This topic shows how to use the SplitPdf plugin to split a PDF document into several PDF documents. You select the pages in the constructor, and Save writes one document per part. The part number is added to the output file name: page.pdf becomes page_1.pdf, page_2.pdf, and so on.

Prerequisites

Refer to the Developer Guide to learn how to set up your environment and run the code examples in this section.

The Loading Source Documents and Saving Output Documents topics explain how to specify input and output documents.

Split Specific Pages into Separate Documents

The following example puts pages 1, 2, and 3 into documents of their own. Each part is numbered after the source page it holds: page_1.pdf, page_2.pdf, and page_3.pdf.

using System;
using GroupDocs.Merger.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Select pages 1, 2, and 3
var splitter = new SplitPdf("business-plan.pdf", new[] { 1, 2, 3 });

// Save one document per part
splitter.Save("output/page.pdf");
Imports System
Imports GroupDocs.Merger.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Select pages 1, 2, and 3
        Dim splitter As New SplitPdf("business-plan.pdf", {1, 2, 3})

        ' Save one document per part
        splitter.Save("output/page.pdf")
    End Sub
End Module
open System
open GroupDocs.Merger.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Select pages 1, 2, and 3
    let splitter = SplitPdf("business-plan.pdf", [| 1; 2; 3 |])

    // Save one document per part
    splitter.Save("output/page.pdf")
    0

Expected output: Download pages.zip (3 documents)

Split a Document into Parts at Specific Pages

In SplitMode.Interval, the pages you list mark where each new part starts. The following example cuts an 18-page document before pages 7 and 13: chapter_0.pdf holds pages 1 to 6, chapter_1.pdf holds pages 7 to 12, and chapter_2.pdf holds pages 13 to 18. Interval parts are numbered from 0.

using System;
using GroupDocs.Merger.Domain.Options;
using GroupDocs.Merger.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Start a new part at pages 7 and 13
var splitter = new SplitPdf("business-plan.pdf", new[] { 7, 13 }, SplitMode.Interval);

// Save one document per part
splitter.Save("output/chapter.pdf");
Imports System
Imports GroupDocs.Merger.Domain.Options
Imports GroupDocs.Merger.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Start a new part at pages 7 and 13
        Dim splitter As New SplitPdf("business-plan.pdf", {7, 13}, SplitMode.Interval)

        ' Save one document per part
        splitter.Save("output/chapter.pdf")
    End Sub
End Module
open System
open GroupDocs.Merger.Domain.Options
open GroupDocs.Merger.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Start a new part at pages 7 and 13
    let splitter = SplitPdf("business-plan.pdf", [| 7; 13 |], SplitMode.Interval)

    // Save one document per part
    splitter.Save("output/chapter.pdf")
    0

Expected output: Download chapters.zip (3 documents)

Split a Range of Pages

Pass the first and the last page of a range to put every page of the range into a document of its own. The following example splits out pages 2 to 4.

using System;
using GroupDocs.Merger.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Select pages 2 to 4
var splitter = new SplitPdf("business-plan.pdf", 2, 4);

// Save one document per part
splitter.Save("output/page.pdf");
Imports System
Imports GroupDocs.Merger.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Select pages 2 to 4
        Dim splitter As New SplitPdf("business-plan.pdf", 2, 4)

        ' Save one document per part
        splitter.Save("output/page.pdf")
    End Sub
End Module
open System
open GroupDocs.Merger.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Select pages 2 to 4
    let splitter = SplitPdf("business-plan.pdf", 2, 4)

    // Save one document per part
    splitter.Save("output/page.pdf")
    0

Expected output: Download range.zip (3 documents)

Split Odd or Even Pages of a Range

Add a RangeMode to narrow the range to its odd or even pages. The following example splits out the even pages from 1 to 6: pages 2, 4, and 6.

using System;
using GroupDocs.Merger.Domain.Options;
using GroupDocs.Merger.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Select the even pages from 1 to 6
var splitter = new SplitPdf("business-plan.pdf", 1, 6, RangeMode.EvenPages);

// Save one document per part
splitter.Save("output/even-page.pdf");
Imports System
Imports GroupDocs.Merger.Domain.Options
Imports GroupDocs.Merger.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Select the even pages from 1 to 6
        Dim splitter As New SplitPdf("business-plan.pdf", 1, 6, RangeMode.EvenPages)

        ' Save one document per part
        splitter.Save("output/even-page.pdf")
    End Sub
End Module
open System
open GroupDocs.Merger.Domain.Options
open GroupDocs.Merger.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Select the even pages from 1 to 6
    let splitter = SplitPdf("business-plan.pdf", 1, 6, RangeMode.EvenPages)

    // Save one document per part
    splitter.Save("output/even-page.pdf")
    0

Expected output: Download even-pages.zip (3 documents)

Name the Parts with a File Name Template

When the output file name contains {0}, the part number replaces it instead of being added at the end. The following example produces business-plan-page-1.pdf and business-plan-page-2.pdf.

using System;
using GroupDocs.Merger.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Select pages 1 and 2
var splitter = new SplitPdf("business-plan.pdf", new[] { 1, 2 });

// Save one document per part
splitter.Save("output/business-plan-page-{0}.pdf");
Imports System
Imports GroupDocs.Merger.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Select pages 1 and 2
        Dim splitter As New SplitPdf("business-plan.pdf", {1, 2})

        ' Save one document per part
        splitter.Save("output/business-plan-page-{0}.pdf")
    End Sub
End Module
open System
open GroupDocs.Merger.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Select pages 1 and 2
    let splitter = SplitPdf("business-plan.pdf", [| 1; 2 |])

    // Save one document per part
    splitter.Save("output/business-plan-page-{0}.pdf")
    0

Expected output: Download template.zip (2 documents)

Split a Document from a Stream

The source document can also be a Stream. It is read from the beginning, whatever its current position, and it stays open after Save.

using System;
using System.IO;
using GroupDocs.Merger.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Open the source document as a stream
using var stream = File.OpenRead("business-plan.pdf");

// Select pages 1 and 2
var splitter = new SplitPdf(stream, new[] { 1, 2 });

// Save one document per part
splitter.Save("output/page.pdf");
Imports System
Imports System.IO
Imports GroupDocs.Merger.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Open the source document as a stream
        Using stream = File.OpenRead("business-plan.pdf")
            ' Select pages 1 and 2
            Dim splitter As New SplitPdf(stream, {1, 2})

            ' Save one document per part
            splitter.Save("output/page.pdf")
        End Using
    End Sub
End Module
open System
open System.IO
open GroupDocs.Merger.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Open the source document as a stream
    use stream = File.OpenRead("business-plan.pdf")

    // Select pages 1 and 2
    let splitter = SplitPdf(stream, [| 1; 2 |])

    // Save one document per part
    splitter.Save("output/page.pdf")
    0

Expected output: Download from-stream.zip (2 documents)