Split Word Documents using REST API in Ruby

How to Split Word Documents using REST API in Ruby
How to Split Word Documents using REST API in Ruby?

Long word documents require a lot of team work and it’s necessary to split it into multiple shorter documents for working faster in word. Instead of cutting and pasting long documents, we have more fast cloud APIs to split word documents into several files programmatically. By splitting word documents, you can easily extract and share a specific piece of information or a set of data with the stakeholders. As a Ruby developer, you can split word documents into multiple documents on the cloud. In this article, you will learn¬†how to¬†split word documents using REST API in Ruby.

The following topics shall be covered in this article:

Word DOCX Splitter Cloud API and Ruby SDK

For splitting word files, I will be using the Ruby 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 drawingsPDF, and HTML.

You can install GroupDocs.Merger Cloud SDK to your Ruby application using the following command in the terminal:

gem install groupdocs_conversion_cloud

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

Split Word Documents into One-Page Documents in Ruby

You can split word files programmatically on the cloud by following the simple steps mentioned below. Upload the word file to the cloud and then download file from the cloud using REST API. You can easily split pages of any word file into separated word documents consisting of one page in a document programmatically by following the steps given below:

  • Create an instance of the DocumentApi.
  • Create an instance of the FileInfo.
  • Next, set path to the input word docx file.
  • Create an instance of the SplitOptions.
  • Then, assign FileInfo to the SplitOptions.
  • Set output path and specific page numbers in a comma separated array to split document.
  • Now, set document split mode to Pages. It allows API to split page numbers given in comma separated array as a separate word documents.
  • Create SplitRequest with SplitOptions.
  • 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 Ruby.

The above code sample will save the separated single files on the cloud.

How to Split Word DOCX into Multi-Page Word Documents

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.
  • Next, set path to the input word docx file.
  • Create an instance of the SplitOptions.
  • Then, assign FileInfo to the SplitOptions.
  • Set output path and specific page numbers in a comma separated array to split document.
  • Now, set document split mode to Intervals. It allows API to split page numbers given in comma separated array as a separate word documents.
  • Create SplitRequest with SplitOptions.
  • Finally, call the DocumentAPI.split() method with SplitRequest and get results.

The following code snippet shows how to split word file into multi-page word documents using REST API in Ruby.

Split Document to Single Page Documents by Providing Exact Page Number

You can 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.
  • Next, set path to the input word docx file.
  • Create an instance of the SplitOptions.
  • Then, assign FileInfo to the SplitOptions.
  • Set output path, start_page_number and end_page_number to split document.
  • Now, set document split mode to pages.
  • Create SplitRequest with SplitOptions.
  • Finally, call the DocumentAPI.split() method with SplitRequest and get results.

The following code snippet shows how to split word file by page exact numbers in Ruby using REST API.

Split Document to One-Page Documents by Applying Filter

You can 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.
  • Next, set path to the input word docx file.
  • Create an instance of the SplitOptions.
  • Then, assign FileInfo to the SplitOptions.
  • Set output path, start_page_number and end_page_number to split document.
  • Now, set document range_mode to OddPages and split mode to Intervals.
  • Create SplitRequest with SplitOptions.
  • Finally, call the DocumentAPI.split() method with SplitRequest and get results.

The following code snippet shows how to split word file by applying filter using REST API in Ruby.

Free Online Split Word Document

How to Split Word File Online? Using free online Word Document Splitter, you can split word document into multiple documents by a fixed number of pages, in various page ranges. Multiple pages Word documents are divided into multiple Word documents keeping the layout of the source document.

Conclusion

In this tutorial, we have learned how to split word documents using REST API in Ruby on the cloud. Moreover, you have seen how to split word files into multi-page word documents programmatically. Moreover, you can learn more about GroupDocs.Merger Cloud API using the documentation. We also provide an API Reference section that lets you visualize and communicate with our APIs directly through the browser.

Ask a question

If you have any questions about Word DOCX Splitter, please feel free to ask us on the Forum

See Also