Rearrange PDF Pages: Move, Swap and Delete PDF Pages in Ruby

How to Move, Swap and Delete PDF Pages in Ruby

PDF is the most popular format and the industry standard for sharing and printing documents. In certain cases, we may need to swap pdf pages or rearrange pages pdf. We can reorganize pdf pages into well-structured documents by moving or swapping specific pages within PDF documents programmatically on the cloud. In this article, we will learn how to rearrange PDF pages using REST API in Ruby.

The following topics shall be covered to rearrange pdfs in this article:

Rearrange PDF Pages REST API and Ruby SDK

To organise pdf pages or reorder pdf pages online free, we will be using the Ruby SDK of GroupDocs.Merger Cloud API. It allows us to split, combine, remove unwanted pages from pdf. You can also rearrange page order in pdf for a single page or a collection of pages within supported document formats. Please install it using the following command in the console:

gem 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:

Now, follow the below steps to reorder pages of pdf, delete and rearrange pdf pages on your phone or tablet.

How to Rearrange Pages in a PDF Document using Ruby

We can rearrange pages by moving any page to a new position in PDF document programmatically on the cloud by following the steps given below. Firstly, you can upload the PDF file to the cloud and as a result, the uploaded PDF file will be available in the files section of the dashboard on the cloud. Now, we will move pdf pages by following the steps given below:

  • Firstly, create an instance of the PagesApi.
  • Next, create an instance of the MoveOptions.
  • Then, create an instance of the FileInfo.
  • Set the input PDF file path and output file path
  • Next, set the current page number and new page number.
  • After that, create the MoveRequest with MoveOptions as an argument.
  • Finally, call the **move()** method and save the updated document.

The following code sample shows how to move pages in a pdf file using REST API in Ruby:

Finally, the above code sample will save the organized pages PDF file on the cloud. How to rearrange pages in PDF for free? Please try the following free online pdf combiner and reorder tool, which is developed using the above API.

How to Swap PDF Pages using REST API using Ruby

We can swap the position of two pages within a PDF document by following the steps given below:

  • Firstly, create an instance of the PagesApi.
  • Next, create an instance of the SwapOptions.
  • Then, create an instance of the FileInfo.
  • Set the input PDF file path and output file path
  • Next, set the current page number and new page number.
  • After that, create the SwapRequest with SwapOptions as an argument.
  • Finally, call the swap() method and save the updated document.

The following code sample shows how to change the order of pages in PDF document using REST API in Ruby:

Finally, the above code sample will save the swapped PDF pages on the cloud. How to reorder pages pdf? Please try the following free online tool to swap and change order of PDF pages online, which is developed using the above API.

How to Remove Multiple Pages from PDF using Ruby

We can remove extra page in PDF document by following the steps given below:

  • Firstly, create an instance of the PagesApi.
  • Next, create an instance of the RemoveOptions.
  • Then, create an instance of the FileInfo.
  • Set the input PDF file path and output file path
  • Now, provide the comma separated page numbers to be deleted.
  • After that, create the RemoveRequest with RemoveOptions as an argument.
  • Finally, call the remove() method and save the updated document.

The following code sample shows how to swap two pages within a PDF document using a REST API in Ruby:

Finally, the above code sample will remove the deleted PDF pages from the cloud. How to delete pdf pages online free? Please try the following pdf page remover online tool to delete pages from pdf free, which is developed using the above API.

Summing up

In this article, we have learned:

  • how to change order of pages in pdf;
  • swap and reorder pdf pages free;
  • page delete in pdf file and pdf online page remover;

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. Moreover, groupdocs.cloud is writing new blog posts on other interesting topics. Therefore, please stay in touch for regular updates.

Ask a question

For queries about how to rearrange and delete pdf pages, feel free to ask us via the Forum

See Also