January 2019
Beginner
318 pages
8h 23m
English
In this section, we are going to see how to rotate PDF pages. For that, we will use the rotate.Clockwise() method of a PDF object. Create a script called rotate_pdf.py and write the following content in it:
import PyPDF2with open('test.pdf', 'rb') as pdf: rd_pdf = PyPDF2.PdfFileReader(pdf) wr_pdf = PyPDF2.PdfFileWriter() for pg_num in range(rd_pdf.numPages): pdf_page = rd_pdf.getPage(pg_num) pdf_page.rotateClockwise(90) wr_pdf.addPage(pdf_page) with open('rotated.pdf', 'wb') as pdf_out: wr_pdf.write(pdf_out)print("pdf successfully rotated")
Run the script and you will get the following output:
student@ubuntu:~/work$ python3 rotate_pdf.py
Following is the output:
pdf successfully rotated
In the preceding example, for the ...
Read now
Unlock full access