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 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.
usingSystem;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Select pages 1, 2, and 3varsplitter=newSplitDocx("business-plan.docx",new[]{1,2,3});// Save one document per partsplitter.Save("output/page.docx");
ImportsSystemImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Select pages 1, 2, and 3
DimsplitterAsNewSplitDocx("business-plan.docx",{1,2,3})' Save one document per part
splitter.Save("output/page.docx")EndSubEndModule
openSystemopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Select pages 1, 2, and 3
letsplitter=SplitDocx("business-plan.docx",[|1;2;3|])// Save one document per part
splitter.Save("output/page.docx")0
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.
usingSystem;usingGroupDocs.Merger.Domain.Options;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Start a new part at pages 7 and 13varsplitter=newSplitDocx("business-plan.docx",new[]{7,13},SplitMode.Interval);// Save one document per partsplitter.Save("output/chapter.docx");
ImportsSystemImportsGroupDocs.Merger.Domain.OptionsImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Start a new part at pages 7 and 13
DimsplitterAsNewSplitDocx("business-plan.docx",{7,13},SplitMode.Interval)' Save one document per part
splitter.Save("output/chapter.docx")EndSubEndModule
openSystemopenGroupDocs.Merger.Domain.OptionsopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Start a new part at pages 7 and 13
letsplitter=SplitDocx("business-plan.docx",[|7;13|],SplitMode.Interval)// Save one document per part
splitter.Save("output/chapter.docx")0
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.
usingSystem;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Select pages 2 to 4varsplitter=newSplitDocx("business-plan.docx",2,4);// Save one document per partsplitter.Save("output/page.docx");
ImportsSystemImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Select pages 2 to 4
DimsplitterAsNewSplitDocx("business-plan.docx",2,4)' Save one document per part
splitter.Save("output/page.docx")EndSubEndModule
openSystemopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Select pages 2 to 4
letsplitter=SplitDocx("business-plan.docx",2,4)// Save one document per part
splitter.Save("output/page.docx")0
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.
usingSystem;usingGroupDocs.Merger.Domain.Options;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Select the even pages from 1 to 6varsplitter=newSplitDocx("business-plan.docx",1,6,RangeMode.EvenPages);// Save one document per partsplitter.Save("output/even-page.docx");
ImportsSystemImportsGroupDocs.Merger.Domain.OptionsImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Select the even pages from 1 to 6
DimsplitterAsNewSplitDocx("business-plan.docx",1,6,RangeMode.EvenPages)' Save one document per part
splitter.Save("output/even-page.docx")EndSubEndModule
openSystemopenGroupDocs.Merger.Domain.OptionsopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Select the even pages from 1 to 6
letsplitter=SplitDocx("business-plan.docx",1,6,RangeMode.EvenPages)// Save one document per part
splitter.Save("output/even-page.docx")0