How to Rotate PDF Pages using Rest API in Node.js

How to Rotate PDF Pages using Rest API in Node.js

In this article, we will demonstrate the scenarios related to rotation in PDF files at defining degrees. You can rotate all PDF pages at once or specific PDF pages into any direction permanently according to your requirements. Moreover, you can choose the angle to rotate the PDF pages like 90 degrees rotation or rotate PDF pages at 180 degrees. In this article, we will learn how to rotate PDF pages using REST API in Node.js.

The following topics shall be covered in this article:

PDF Pages Rotation Rest API and Node.js SDK

In order to rotate pages from PDF adobe acrobat, I will be using the Node.js SDK of GroupDocs.Merger Cloud API. It is online PDF page rotation free download library. It allows you to split, combine, extract, 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 to rotate PDF pages in your Node.js application using the following command in the console:

npm install groupdocs-conversion-cloud

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

Rotate All Pages of a PDF Document using Node.js

You can rotate PDF pages in a PDF document programmatically on the cloud by following the steps given below. First, upload the PDF file to the cloud and the uploaded PDF file will be available in the files section of the dashboard on the cloud. There could be many use cases where you need to rotate PDF files. You can rotate all pages of a PDF file by following the steps given below:

  • Firstly, create an instance of the PagesApi
  • Next, create an instance of the RotateOptions
  • Then, create an instance of the FileInfo
  • Provide the input PDF document path and output file path
  • Next, set the desired page rotation like Rotate90
  • After that, create the RotateRequest with RotateOptions as an argument
  • Finally, call the rotate() method and save the output PDF document

The following code snippet shows how to rotate all pages of a PDF file using REST API in Node.js:

Finally, the above code sample will save the updated PDF file on the cloud. You can download upload file using code snippet.

Rotate Specific Pages of PDF File using Node.js SDK

The rotation in a PDF document is applied on page level. Therefore, you can also rotate specific pages of PDF file as per your requirements. You only need to choose the page number you want to apply the rotation on. The steps below explain how to rotate certain pages of PDF file:

  • Firstly, create an instance of the PagesApi
  • Next, create an instance of the RotateOptions
  • Then, create an instance of the FileInfo
  • Provide the input PDF document path and output file path
  • Assign the exact page numbers using pages collection
  • Set the desired page rotation like Rotate90, Rotate180 or Rotate270
  • After that, create the RotateRequest with RotateOptions as an argument
  • Finally, call the rotate() method and save the output PDF document

The following code snippet elaborates how to rotate specific or certain pages in a PDF document using Node.js:

Finally, the above code sample will save the output PDF file on the cloud.

Rotate PDF Pages By Page Number using Node.js SDK

You can also rotate PDF pages by page number. You need to provide the start page number and end page number to apply the rotation. The steps below explain how to rotate PDF pages by page numbers of a PDF file:

  • Firstly, create an instance of the PagesApi
  • Next, create an instance of the RotateOptions
  • Then, create an instance of the FileInfo
  • Provide the input PDF document path and output file path
  • Set the start page number and end page number values;
  • Set the desired page rotation like Rotate270
  • After that, create the RotateRequest with RotateOptions as an argument
  • Finally, call the rotate() method and save the output PDF document

The code snippet below shows how to rotate pages in PDF document by providing page numbers using Node.js Rest API:

The above code example will save the output PDF document on the cloud.

Online Rotate PDF Pages for Free

Please try the following free online tool to rotate PDF document pages, which is developed using the above API.

Summing up

In this article, you have learned:

  • how to rotate all pages of a PDF document online using Node.js;
  • programmatically rotate certain pages of a PDF file using Node.js;
  • how to rotate PDF Pages by page number and range mode using Node.js;

Additionally, 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

If you have any queries about PDF pages rotation, please feel free to ask us at Free Support Forum

See Also