[Python] How to rotate a page by arbitrary angle in pymupdf?

Discussão em 'Python' iniciado por Stack, Agosto 18, 2025.

  1. Stack

    Stack Membro Participativo

    I couldn't find how to rotate a text page of a PDF by an arbitraty angle in the pymupdf documentation.

    There is page.set_rotation(angle), however, which only allows for 0, 90, 180, 270 degrees, which is also combined in case of 90 and 270 degrees by a page orientation change.

    So, I was hoping for something like:

    import pymupdf

    doc = pymupdf.open("Rest.pdf") # open document
    page = doc[0] # get the 1st page of the document
    page.set_rotation(0) # rotate the page

    matrix = pymupdf.Matrix(1,0,0,1,0,0)
    matrix.prerotate(2.5) # 2.5 degrees

    page.add_transformation(matrix) # BUT THIS DOES NOT EXIST!

    doc.save("Test_rotated.pdf")


    Can this be done at all? Or do I maybe have to convert the text to an image and then rotate that image? Thank you for any hints.

    Continue reading...

Compartilhe esta Página