Rotate PDF Pages in Python using PDF.co Web API

Rotating pages from PDF documents can be a repetitive and time-consuming task, particularly when done manually. But with PDF.co PDF Rotate Pages, you can save yourself from the hassle and simplify the process. Our tool is easy to use and requires only a few clicks to rotate your PDF pages to the desired angle. Whether you need to rotate one page or all pages in your document, our tool can handle it easily.

Another advantage of using PDF.co PDF Rotate Pages is that it offers a risk-free service that processes everything on the client side within your browser. This ensures that your data remains secure and private, as the tool does not store or transfer any of your files or data to any external servers.

In this comprehensive guide, we will take you through a step-by-step tutorial on how to utilize Python and PDF.co Web API to rotate PDF pages easily. We’ll cover all the essential aspects, from setting up the necessary environment to making API calls, enabling you to perform PDF page rotation smoothly in your Python projects.

We will use this sample PDF that contains multiple pages, and we’ll demonstrate how to rotate specific pages to the desired angle. Additionally, you have the flexibility to rotate all pages if that suits your preference or meets your specific requirements.

Sample PDF Document with Multiple Pages

Step 1: Open Visual Studio Code Editor

  • To get started, open your preferred code editor, such as Visual Studio Code or any other editor you like.
  • Next, you can use this link to access the source code for the Python sample. Copy and paste the code into your editor to proceed with the next steps.

Step 2: Add PDF.co API Key

  • After adding the sample code for Python, navigate to line 6 and add your API Key. You can obtain the API key from your PDF.co dashboard or by signing up at this link.
Add PDF.co API Key

Step 3: Setup Python Code

Let’s proceed with setting up the Python code to rotate PDF pages.

  • First, find line 13 in the code and provide the direct URL of your source PDF file. If you are using a file instead of a URL, you can use the PDF.co File Storage to store your files and convert them into a URL specifically for use in PDF.co processing.
  • Next, navigate to line 16 and input the angle value by which you want to rotate the PDF pages.
  • Then, go to line 19 and add the list of specific pages you wish to rotate. Alternatively, you can rotate all pages in the PDF document, depending on your specific requirements.
  • Lastly, enter the desired output file name to save the rotated PDF.
Setup Python Code


After setting up the code and making any necessary changes, be sure to save the file. Then, click the Run button to start executing the program.

Step 4: Run Program Result

  • Awesome! The program runs successfully and returns the PDF file output. Let’s check the program folder path to view the output.
Run Program Result

Step 5: Navigate to Program Folder

  • Let’s navigate to the program folder and click on the PDF file to display the rotated pages as per the specified angle and page selection.
Check Program Folder

Step 6: PDF Rotated Pages Output

  • Here is the PDF document containing the rotated pages as per the specified angle and page selection.
PDF Rotated Pages Output

In this tutorial, you gained valuable knowledge on how to rotate pages from a PDF document using Python and PDF.co Web API. Feel free to explore further and apply this newfound skill to enhance your PDF processing capabilities.

Video Guide