Split PDF Files using REST API in Ruby

How to Split PDF Files using REST API in Ruby.
How to Separate and Split PDF Files using REST API in Ruby

Long PDF files require a lot of team work and it’s necessary to split it into multiple shorter documents for working faster in PDF. Instead of cutting and pasting long documents, we have more fast cloud APIs to split PDF documents into several files programmatically. By splitting PDF 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 PDF documents into multiple documents on the cloud. In this article, you will learn how to split PDF files using REST API in Ruby.

The following topics shall be covered in this article:

PDF File Splitter REST API and Ruby SDK

For splitting PDF 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, PowerPointVisio drawings, 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 PDF Files into One-Page Documents using Ruby

You can split PDF files programmatically on the cloud by following the simple steps mentioned below. Upload the PDF file on the cloud and then download it from the cloud using REST API. You can easily split pages of any PDF file into separated PDF 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 PDF 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 PDF 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 PDF file using a REST API in Ruby.

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

How to Split PDF Files into Multi-Page PDF using Ruby

You can split PDF files into multipage PDF 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 PDF 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 PDF documents.
  • Create SplitRequest with SplitOptions.
  • Finally, call the DocumentAPI.split() method with SplitRequest and get results.

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

Split PDF to Single Page Files by Providing Exact Page Number

You can extract and save pages from a PDF 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 PDF 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 PDF file by page exact numbers in Ruby using REST API.

Split PDF to One-Page Files by Applying Filter using Ruby

You can extract and save pages from a PDF 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 PDF 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 PDF file by applying filter using REST API in Ruby.

Free Online Split PDF Files

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

Summing up

In this tutorial, we have learned how to split PDF documents using REST API in Ruby on the cloud. Moreover, you have seen how to split PDF files into multi-page PDF 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 PDF Splitter, please feel free to ask us on the Forum

See Also