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

Using SplitDocx to Split DOCX Documents

This topic shows how to use the SplitDocx plugin to split a DOCX document into several DOCX 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.docx becomes page_1.docx, page_2.docx, 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.docx, page_2.docx, and page_3.docx.

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 SplitDocx("business-plan.docx", new[] { 1, 2, 3 });

// Save one document per part
splitter.Save("output/page.docx");
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 SplitDocx("business-plan.docx", {1, 2, 3})

        ' Save one document per part
        splitter.Save("output/page.docx")
    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 = SplitDocx("business-plan.docx", [| 1; 2; 3 |])

    // Save one document per part
    splitter.Save("output/page.docx")
    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.docx holds pages 1 to 6, chapter_1.docx holds pages 7 to 12, and chapter_2.docx 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 SplitDocx("business-plan.docx", new[] { 7, 13 }, SplitMode.Interval);

// Save one document per part
splitter.Save("output/chapter.docx");
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 SplitDocx("business-plan.docx", {7, 13}, SplitMode.Interval)

        ' Save one document per part
        splitter.Save("output/chapter.docx")
    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 = SplitDocx("business-plan.docx", [| 7; 13 |], SplitMode.Interval)

    // Save one document per part
    splitter.Save("output/chapter.docx")
    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 SplitDocx("business-plan.docx", 2, 4);

// Save one document per part
splitter.Save("output/page.docx");
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 SplitDocx("business-plan.docx", 2, 4)

        ' Save one document per part
        splitter.Save("output/page.docx")
    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 = SplitDocx("business-plan.docx", 2, 4)

    // Save one document per part
    splitter.Save("output/page.docx")
    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 SplitDocx("business-plan.docx", 1, 6, RangeMode.EvenPages);

// Save one document per part
splitter.Save("output/even-page.docx");
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 SplitDocx("business-plan.docx", 1, 6, RangeMode.EvenPages)

        ' Save one document per part
        splitter.Save("output/even-page.docx")
    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 = SplitDocx("business-plan.docx", 1, 6, RangeMode.EvenPages)

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

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