Skip to content

Replace page orientation #2384

May 5, 2023 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

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")

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@sebastianvao
Comment options

Answer selected by JorjMcKie
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@JorjMcKie
Comment options

@JorjMcKie
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants