Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import PyPDF2
- def rotate_even_pages(input_pdf, output_pdf):
- # Open the input PDF
- with open(input_pdf, 'rb') as infile:
- reader = PyPDF2.PdfReader(infile)
- writer = PyPDF2.PdfWriter()
- # Iterate over all the pages
- num_pages = len(reader.pages)
- for i in range(num_pages):
- page = reader.pages[i]
- # Rotate only the even pages (index 1, 3, 5, etc.)
- if i % 2 == 1: # 1-based index for even pages: 2, 4, 6, etc.
- page.rotate(180)
- writer.add_page(page)
- # Write the output PDF
- with open(output_pdf, 'wb') as outfile:
- writer.write(outfile)
- # Example usage
- input_pdf = 'input.pdf' # Replace with your input PDF file
- output_pdf = 'output.pdf' # Replace with your desired output PDF file
- rotate_even_pages(input_pdf, output_pdf)
- print(f"Processed PDF saved as '{output_pdf}'")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement