[![Aspose.PDF Cloud logo][1] is a file format used to present documents in a manner that is independent of application software, hardware, and operating systems. It is now an open standard for electronic document exchange maintained by the International Organization for Standardization (ISO). When you share a PDF file, virtually anyone can read it using free apps.

Aspose.PDF Cloud allows you to create, read, update or convert PDFs in any language including .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more. You can use it with any language or platform that supports REST. (Almost all platforms and languages support REST and provide native REST clients to work with REST APIs.)

This post covers how to split a multipage PDF into single pages and save all or specific pages as DOC, PDF, PDF a1a, PDF a1b, XPS, TIFF, JPEG, PNG, EMF, BMP and GIF formats in RUBY. You can check [Split PDF Files][2] for other languages. To split PDFs, upload the input PDFs to Aspose Cloud or any supported third party storage and then send a POST request to the Aspose Cloud service. The following steps describe the process in detail.

Split a PDF Using RUBY REST

This REST example uses the RestClient library to send HTTP request and handle HTTP response so you need to install RestClient to use these examples.

You can use the following URI to split a PDF on Aspose Cloud or any supported third party storage: http://api.aspose.com/v1.1/pdf/Input1.pdf/split

You can use following optional parameters with the above mentioned URI. All or specific parameters can be used according to your requirement. If no parameter is specified, then all pages will be split to PDF format.

  • storage – used to set storage name if you are using a third party storage.
  • folder – used to set the name/path of the folder where input file has been uploaded.
  • from – used to set the start page number if you are splitting specific pages.
  • to – used to set the end page number if you are splitting specific pages.
  • format – used to set output format. If not specified, PDF will be used as default format.

After building the URI, go through the following steps:

  1. Set the App SID and App Key and sign the URI.
    See section 1 of the following code and the [Sign URI][3] method for more details.
  2. Send a POST request to Aspose Cloud service.
    See section 2 of the following code for more details.

Following is the code to split a PDF.

####### Section 1 ######  
app_sid  **=**  '####### Section 1 ######  

app_sid  **=**  '77******-1***-4***-a***-80**********'  

app_key  **=**  '*********************'  

Aspose**::Cloud::**Common**::**AsposeApp**.**new**(**app_sid**,** app_key**)**  

#build URI to split PDF  

str_uri  **=**  'http://api.aspose.com/v1.1/pdf/Input1.pdf/split'**;**  

#uncomment following line to split specific pages  

#str_uri = 'http://api.aspose.com/v1.1/pdf/Input1.pdf/split?from=2&to=3&format=tiff'; 

#sign URI

signed_uri  **=** Aspose**::Cloud::**Common**::**Utils**.**sign**(**str_uri**);**

  ####### End Section 1 ######

  ####### Section 2 ######

#Split PDF file

response_stream  **=** RestClient**.**post**(**signed_uri**,**  ''**,**  **{**:accept**=>**:json**})**
####### End Section 2 ###### 

Download Split Files

Once the files are split, you can download the pages as new files. To download split files, convert the response stream to JSON and loop through each Href element to get the files names and download those files.

Following is the code to download split files.

`stream_hash  **=** JSON**.**parse**(**response_stream**)**
  
stream_hash**[**'Result'**][**'Documents'**].**each **do**  **|**document**|**

  #Build and sign URI to download split files

 file_name **=** File**.**basename**(**document**[**'Href'**])**

 str_uri **=**  'http://api.aspose.com/v1.1/storage/file/'  **+** file_name**;**  

 signed_uri **=** Aspose**::Cloud::**Common**::**Utils**.**sign**(**str_uri**);**

 p signed_uri

 file_name **=** File**.**basename**(**str_uri**)**

  #Download and save split PDF files

 response_stream **=** RestClient**.**get**(**signed_uri**,** :accept **=>**  'application/json'**)**

 Aspose**::Cloud::**Common**::**Utils**.**save_file**(**response_stream**,** file_name**)**

**end**` 

[1]: https://blog.aspose.com/wp-content/uploads/sites/2/2014/02/aspose_pdf_for_cloud_140px-e1393511150928.png “Aspose.PDF Cloud logo”)](https://blog.aspose.com/wp-content/uploads/sites/2/2014/02/aspose_pdf_for_cloud_140px-e1393511150928.png)Portable Document Format (PDF [2]: http://www.aspose.com/docs/display/pdfcloud/Split+PDF+Files [3]: http://www.aspose.com/docs/display/rest/REST+API+Methods