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
- Configure the environment to use Aspose.PDF for Python via .NET to rotate text in a PDF
- Create a new Pdf file using the Document class object to add rotated text
- Add a page and set some sample text using TextFragment object
- Set the text position on the page and set the rotation angle of the text
- Instantiate the TextBuilder object for the selected page and append the fragment using it
- 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.