Replace page orientation #2384
-
Hello, I also tried setting the Is there any easy way of doing that? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Yes, there is: import fitz
doc = fitz.open() # new output file
src = fitz.open("input.pdf") # source file
for src_page in src: # iterate over input pages
src_rect = src_page.rect # source page rect
w, h = src_rect.br # save its width, height
src_rot = src_page.rotation # save source rotation
src_page.set_rotation(0) # set rotation to 0 temporarily
page = doc.new_page(width=w, height=h) # make output page
page.show_pdf_page( # insert source page
page.rect,
src,
src_page.number,
rotate=-src_rot, # use reversed original rotation
)
doc.ez_save("output.pdf") |
Beta Was this translation helpful? Give feedback.
-
Thank you very much, that's exactly was I was looking for. |
Beta Was this translation helpful? Give feedback.
-
There would be a way of doing the same keeping annotations, widgets and so on? |
Beta Was this translation helpful? Give feedback.
Yes, there is: