Split Large Documents
Use the Wordize Splitting for .NET module to split your documents into parts.
Select any document conversion module to work with the required formats.
Wordize provides the Wordize Splitting for .NET module, which allows users to split large documents into multiple smaller documents programmatically. This feature is useful for dividing large content into manageable sections on a page-by-page basis, as well as based on sections, page ranges, and paragraph styles.
Additionally, Wordize allows you to remove blank pages from your documents to improve readability and ensure a professional appearance, as well as reduce file size and prevent printing unnecessary pages.
Let’s look at each of these methods in more detail.
Split Page by Page
Wordize allows users to split a document by pages. To do this, you need to use the Page value of the SplitCriteria property in the SplitOptions class.
So, if you have a document of 5 pages, then using this method of splitting the document you will get 5 documents with 1 page each.
The following code example shows how to split a document by pages using the Split(string, string, SplitOptions) method:
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.Page;
Splitter.Split(doc, "SplitDocument.1.docx", options);
If the input document is PDF, the split criteria is Page, and the output document has a fixed page format (where the geometry of objects and their position on the page are fixed, such as PDF or image formats), for better performance and fidelity, the split is performed without reading PDF documents into the internal flow Document Object Model.
Find a full list of code examples for splitting documents in the Split a Document Code Examples section at the bottom of the page.
Split by Sections
Wordize also allows to use section breaks to split documents into sections. For this purpose, use the SectionBreak value of the SplitCriteria property in the SplitOptions class.
The following code example shows how to split a document into sections using the Split(string, string, SplitOptions) method:
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.SectionBreak;
Splitter.Split(doc, "SplitDocument.3.docx", options);
Find a full list of code examples for splitting documents in the Split a Document Code Examples section at the bottom of the page.
Split by Styles
Wordize allows you to split a document into parts by paragraph, formatted with a specific style. To split a document by paragraphs, use the Style value of the SplitCriteria property and define styles using the SplitStyle property.
The following code example shows how to split a document into parts by paragraph style using the Split(string, string, SplitOptions) method:
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.Style;
options.SplitStyle = "Heading 1";
Splitter.Split(doc, "SplitDocument.5.docx", options);
Find a full list of code examples for splitting documents in the Split a Document Code Examples section at the bottom of the page.
Split by Page Ranges
Wordize allows you to extract a specific page ranges from a multi-page document. Just select a range of pages and keep only that part of the original document using the ExtractPages method.
The following code example shows how to split a document by page ranges using the ExtractPages(string, string, int, int) method:
string doc = "BigDocument.docx";
Splitter.ExtractPages(doc, "ExtractPages.1.docx", 0, 2);
Find a full list of code examples for splitting documents in the Split a Document Code Examples section at the bottom of the page.
Remove Blank Pages
You can also remove blank pages from the document.
The following code example shows how to do this using the RemoveBlankPages(string, string) method:
string doc = "BlankPages.docx";
Splitter.RemoveBlankPages(doc, "RemoveBlankPages.1.docx");
Split a Document Code Examples
Wordize provides both a Standard API and a Fluent API, allowing developers to choose the most convenient approach for their needs.
Wordize API
Split by Pages
The following code examples show how to split a document page by page, using one of the Split methods.
method Split(string, string, SplitOptions)
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.Page;
Splitter.Split(doc, "SplitDocument.1.docx", options);
method Split(string, string, SaveFormat, SplitOptions)
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.Page;
Splitter.Split(doc, "SplitDocument.2.docx", SaveFormat.Docx, options);
method Split(Stream, SaveFormat, SplitOptions)
using var streamIn = File.OpenRead("BigDocument.docx");
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.Page;
Stream[] stream = Splitter.Split(streamIn, SaveFormat.Docx, options);
Split into Sections
The following code examples show how to split a document into sections, using one of the Split methods.
method Split(string, string, SplitOptions)
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.SectionBreak;
Splitter.Split(doc, "SplitDocument.3.docx", options);
method Split(string, string, SaveFormat, SplitOptions)
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.SectionBreak;
Splitter.Split(doc, "SplitDocument.4.docx", SaveFormat.Docx, options);
method Split(Stream, SaveFormat, SplitOptions)
using var streamIn = File.OpenRead("BigDocument.docx");
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.SectionBreak;
Stream[] stream = Splitter.Split(streamIn, SaveFormat.Docx, options);
Split by Style
The following code examples show how to split a document into parts by paragraph style, using one of the Split methods.
method Split(string, string, SplitOptions)
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.Style;
options.SplitStyle = "Heading 1";
Splitter.Split(doc, "SplitDocument.5.docx", options);
method Split(string, string, SaveFormat, SplitOptions)
string doc = "BigDocument.docx";
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.Style;
options.SplitStyle = "Heading 1";
Splitter.Split(doc, "SplitDocument.6.docx", SaveFormat.Docx, options);
method Split(Stream, SaveFormat, SplitOptions)
using var streamIn = File.OpenRead("BigDocument.docx");
SplitOptions options = new SplitOptions();
options.SplitCriteria = SplitCriteria.Style;
Stream[] stream = Splitter.Split(streamIn, SaveFormat.Docx, options);
Split by Page Ranges
The following code examples show how to split a document by page ranges, using one of the ExtractPages methods.
method ExtractPages(string, string, int, int)
string doc = "BigDocument.docx";
Splitter.ExtractPages(doc, "ExtractPages.1.docx", 0, 2);
method ExtractPages(string, string, SaveFormat, int, int)
string doc = "BigDocument.docx";
Splitter.ExtractPages(doc, "ExtractPages.2.docx", SaveFormat.Docx, 0, 2);
method ExtractPages(Stream, Stream, SaveFormat, int, int)
using var streamIn = File.OpenRead("BigDocument.docx");
using var streamOut = File.Create("UnsignedDocument.docx");
Splitter.Split(streamIn, streamOut, SaveFormat.Docx, 0, 2);
Remove Blank Pages
The following code examples show how to remove blank pages from a document, using one of the RemoveBlankPages methods.
method RemoveBlankPages(string, string)
string doc = "BlankPages.docx";
Splitter.RemoveBlankPages(doc, "RemoveBlankPages.1.docx");
method RemoveBlankPages(string, string, SaveFormat)
string doc = "BlankPages.docx";
Splitter.RemoveBlankPages(doc, "RemoveBlankPages.2.docx", SaveFormat.Docx);
method RemoveBlankPages(Stream, Stream, SaveFormat)
using var streamIn = File.OpenRead("BigDocument.docx");
using var streamOut = File.Create("UnsignedDocument.docx");
Splitter.Split(streamIn, streamOut, SaveFormat.Docx);
Wordize Fluent API
Within the Fluent API, there is a context. SplitterContext allows you to customize the document splitting process using SplitOptions. You cannot split documents without context.
Split by Pages
The following code examples show how to split a document page by page.
method to Split a document by pages and save the result to files
SplitterContext context = new SplitterContext();
context.SplitOptions.SplitCriteria = SplitCriteria.Page;
Splitter.Create(context)
.From("DocumentIn.docx")
.To("DocumentOut.docx")
.Execute();
Note: When saving the output to a file: if the split results in multiple files, a unique name for each part will be generated using the following rule – outputFile_partIndex.extension.
method to Split a document by pages and save the result to a list of streams
SplitterContext context = new SplitterContext();
context.SplitOptions.SplitCriteria = SplitCriteria.Page;
List<Stream> pageStreams = new List<Stream>();
Splitter.Create(context)
.From("DocumentIn.docx")
.To(pageStreams, SaveFormat.Docx)
.Execute();
Split into Sections
The following code examples show how to split a document into sections.
method to Split a document into sections and save the result to files
SplitterContext context = new SplitterContext();
context.SplitOptions.SplitCriteria = SplitCriteria.SectionBreak;
Splitter.Create(context)
.From("DocumentIn.docx")
.To("DocumentOut.docx")
.Execute();
Note: When saving the output to a file: if the split results in multiple files, a unique name for each part will be generated using the following rule – outputFile_partIndex.extension.
method to Split a document into sections and save the result to a list of streams
SplitterContext context = new SplitterContext();
context.SplitOptions.SplitCriteria = SplitCriteria.SectionBreak;
List<Stream> pageStreams = new List<Stream>();
Splitter.Create(context)
.From("DocumentIn.docx")
.To(pageStreams, SaveFormat.Docx)
.Execute();
Split by Style
The following code examples show how to split a document into parts by paragraph style.
method to Split a document by paragraph style and save the result to files
SplitterContext context = new SplitterContext();
context.SplitOptions.SplitCriteria = SplitCriteria.Style;
context.SplitOptions.SplitStyle = "Heading 1";
Splitter.Create(context)
.From("DocumentIn.docx")
.To("DocumentOut.docx")
.Execute();
Note: When saving the output to a file: if the split results in multiple files, a unique name for each part will be generated using the following rule – outputFile_partIndex.extension.
method to Split a document into sections and save the result to a list of streams
SplitterContext context = new SplitterContext();
context.SplitOptions.SplitCriteria = SplitCriteria.Style;
context.SplitOptions.SplitStyle = "Heading 1";
List<Stream> pageStreams = new List<Stream>();
Splitter.Create(context)
.From("DocumentIn.docx")
.To(pageStreams, SaveFormat.Docx)
.Execute();