How to Split Word Document into Separate Files using Node.js

How to Split Word Documents into Separate Files using Node.js

You may need to split the Word document into several smaller files and assign them to different people in order to speed up the process. By splitting Word documents, you can easily extract and share specific information or datasets with stakeholders. As a Node.js developer, you can split word documents into multiple documents on the cloud. Rather than cutting and pasting manually, this article will show you how to split Word document into separate files using Node.js.

The following topics will be covered in this article:

Word DOC Splitter REST API and Node.js SDK

To split Word files, I’m going to use Node.js SDK of GroupDocs.Merger Cloud API. It allows you to split, combine, remove and rearrange a single page or a collection of pages from supported document formats of Word, Excel, PowerPoint, Visio drawings, PDF, and HTML.

You can install GroupDocs.Merger Cloud on your Node.js app with this command in the console:

npm install groupdocs-merger-cloud

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Split Word Document into One-Page Documents using REST API in Node.js

You can split word files programmatically on the cloud by following the simple steps mentioned below:

  • Upload the word file to the Cloud
  • Split word documents using REST API in Node.js
  • Download the separated files

Upload the Word File

First, you’re required to upload the Word file into the cloud using the sample code below:

This will make the downloaded Word file accessible in the [files section][https://dashboard.groupdocs.cloud/files] of your dashboard on the cloud.

Split Word Document using REST API in Node.js

You can easily split pages of any Word file into separate Word documents comprised of a page within a document programmatically by following the steps.

  • Create an instance of the DocumentApi.
  • Create an instance of the FileInfo.
  • Then, set the path to the input word file.
  • Create an instance of SplitOptions.
  • Then, assign File Info to the Split Options.
  • Set specific page numbers in a comma-separated array to split the document.
  • Also, set document split mode to Pages. It allows API to split page numbers given in comma-separated array as separate Word documents.
  • Create SplitRequest with Split Options.
  • Finally, call the DocumentAPI.split() method with SplitRequest and get results.

The following code snippet shows how to split a word file using a REST API in Node.js:

Download the Split Files

The aforementioned code sample will save the divided files to the cloud. Now, you can download files using the following code sample:

Split Word Files into Multipage Word Documents using Node.js

You can split word files into multipage word documents programmatically by following the steps given below:

  • Create an instance of the DocumentApi.
  • Create an instance of the FileInfo.
  • Then, set the path to the input word file.
  • Create an instance of SplitOptions.
  • Then, assign File Info to the Split Options.
  • Set page numbers interval from where to split in a comma-separated array.
  • Also, set the document split mode to Intervals. It allows the API to split document pages based on the page intervals given in a comma-separated array.
  • Create SplitRequest with Split Options.
  • Finally, call the DocumentAPI.split() method with Split Request and get results.

The following code snippet shows how to split a word file into multipage word documents using a REST API in Node.js:

Separate Pages by Page Range using REST API in Node.js

Next, extract and save pages from a Word file by providing a range of page numbers programmatically by following the steps given below:

  • Create an instance of the DocumentApi.
  • Create an instance of the FileInfo.
  • Then, set the path to the input word file.
  • Create an instance of SplitOptions.
  • Then, assign File Info to the Split Options.
  • Set the start page number and the end page number.
  • Also, set document split mode to Pages.
  • Create SplitRequest with Split Options.
  • Finally, call the DocumentAPI.split() method with Split Request and get results.

The following code snippet shows how to split a word file by page numbers range using a REST API in Node.js:

Try Online

Please try the following free online word splitter tool, which is developed using the above API.

Conclusion

In this article, we have learned:

  • how to split word documents using a REST API on the cloud;
  • how to split word files into multipage word documents programmatically;
  • programmatically upload a word file to the cloud and then download the separated files from the cloud;

The API also enables you to reorder or replace document pages, change page orientation, manage document passwords and perform other manipulations easily for any supported file format. Besides, you can learn more about GroupDocs.Merge Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Furthermore, we recommend that you read our Getting Started guide.

Groupdocs.cloud will continue to write articles about new topics. Therefore, please get in touch for the latest updates.

Ask a question

You can ask your queries about how to split word documents, via our Free Support Forum

FAQs

How do I separate pages in a Word document in Node.js?

Please follow Node.js code snippet to learn how to split a word document into multiple files, quickly and easily. You can visit the documentation for complete API details.

See Also

For more information about what we recommend you to visit the following articles: