pypdfium2-team / pypdfium2

Python bindings to PDFium
https://pypdfium2.readthedocs.io/
425 stars 17 forks source link

page.set_rotation() Over Rotating Some Pages #299

Closed MAbdElRaouf closed 8 months ago

MAbdElRaouf commented 8 months ago

Checklist

Description

I have a 4-page PDF where all the pages are visually rotated 270 degrees (90° counterclockwise).

I set the rotation of all pages to 90° (page.set_rotation(90)) and then save to a new file (pdf.save(path)). The problem is the first 2 pages are now correctly rotated (0°), while the last 2 become 90° rotated clockwise.

Running this code to check the original pages' detected rotation and mediabox values:

for page_idx in range(len(pdf_content)):

    page = pdf_content[page_idx]

    print("Page #{}:".format(page_idx), page.get_rotation(), page.get_mediabox())

I found out that the first and last 2 pages have different values:

Page #0: 0 (0.0, 0.0, 595.2000122070312, 841.4400024414062)
Page #1: 0 (0.0, 0.0, 595.2000122070312, 841.4400024414062)
Page #2: 270 (0.0, 0.0, 841.4400024414062, 595.2000122070312)
Page #3: 270 (0.0, 0.0, 841.4400024414062, 595.2000122070312)

Shouldn't page.set_rotation(90) always rotate exactly 90° clockwise regarding of the values above? If not, what would be the correct use of set_rotation in my case?

Thank you.

Install Info

pypdfium2 4.26.0
pdfium 122.0.6233.0 at D:\Python\Lib\site-packages\pypdfium2_raw\pdfium.dll

Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]

Windows-10-10.0.19045-SP0

Name: pypdfium2
Version: 4.26.0
Summary: Python bindings to PDFium
Home-page: https://github.com/pypdfium2-team/pypdfium2
Author: pypdfium2-team
Author-email: geisserml@gmail.com
License: (Apache-2.0 OR BSD-3-Clause) AND LicenseRef-PdfiumThirdParty
Location: \Python\Lib\site-packages
Requires:

Validity