How to split a single Word DOCX into Separate Documents by Page in C# .NET Framework

Cloudmersive
2 min readFeb 9, 2020

--

Today’s lesson will demonstrate for you how to break up a DOCX file into multiple DOCX files, each containing exactly one page of content.

Right out of the gate, we need to begin with installation of our API client. Run this command in Package Manager, and that’s all there is to it.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

Now we can run SplitDocumentDocx on our document in question.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class SplitDocumentDocxExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new SplitDocumentApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.var returnDocumentContents = true;  // bool? | Set to true to return the contents of each Worksheet directly, set to false to only return URLs to each resulting document.  Default is true. (optional)try{// Split a single Word Document DOCX into Separate Documents by PageSplitDocxDocumentResult result = apiInstance.SplitDocumentDocx(inputFile, returnDocumentContents);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling SplitDocumentApi.SplitDocumentDocx: " + e.Message );}}}}

You’re done! Before you go off to celebrate all the time you just saved, you might want to look at our other tutorials, as they cover a wide range of similar functions. These include document editing, converting between formats, and manipulating spreadsheets, to name just a few.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet