How to Rotate Text in PDF using Python

This tutorial explains how to rotate text in PDF using Python. It contains the environment configuration resources, a step-wise detailed procedure to write the application, and a runnable sample code to rotate text in Adobe Acrobat using Python. You will learn the placement of text at the desired location and set the text rotation angle as per your requirements.

Steps to Rotate Text in PDF using Python

  1. Configure the environment to use Aspose.PDF for Python via .NET to rotate text in a PDF
  2. Create a new Pdf file using the Document class object to add rotated text
  3. Add a page and set some sample text using TextFragment object
  4. Set the text position on the page and set the rotation angle of the text
  5. Instantiate the TextBuilder object for the selected page and append the fragment using it
  6. Save the output PDF file having rotated text in it

The aforementioned steps describe the procedure to rotate text on PDF using Python. In this process a new PDF file is created, a page is added to it and then some sample text is set into the TextFragment class for adding to the page at a certain position and angle. Once the text is added to the TextFragment object, it is added to the page using the TextBuilder class object and finally, the output PDF file is saved on the disk.

Code to Rotate Text in Acrobat using Python

The above code segment demonstrates the complete process to rotate text in Acrobat using Python. It uses the Document.pages.add() method to add a new page to the PDF file and then aspose.pdf.text.TextFragment object is instantiated with the sample text to be rotated. The TextFragment class contains properties to rotate the text and also to format the text like setting the font size, name, and foreground/background color if required.

We have learned how to rotate text in Adobe Acrobat using Python. If you want to learn the process to create a PDF file and format its text, refer to the article on how to create PDF in Python.

 English