page.set_rotation() Over Rotating Some Pages #300
-
Checklist
DescriptionI 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° ( 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:
Shouldn't Thank you. Install Infopypdfium2 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: [email protected]
License: (Apache-2.0 OR BSD-3-Clause) AND LicenseRef-PdfiumThirdParty
Location: \Python\Lib\site-packages
Requires: Validity
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Rotation is just a programmatic value to be applied on top of the base coordinate system. It doesn't necessarily align with visuals. From what you've written I'd guess that I'm not aware of a straightforward way to automatically handle cases where visual and programmatic rotation don't match. |
Beta Was this translation helpful? Give feedback.
Rotation is just a programmatic value to be applied on top of the base coordinate system. It doesn't necessarily align with visuals.
set_rotation()
quite simply sets the/Rotation
entry in the PDF's page dictionary. In that sense, it's behaving correctly, even if, in this case, the result does not align with human visual expectations.From what you've written I'd guess that
set_rotation(90)
for page numbers [1,2] andset_rotation(0)
for [3,4] would result in no visual rotation.I'm not aware of a straightforward way to automatically handle cases where visual and programmatic rotation don't match.
You'd probably have to do layout analysis, which is complex and requires much more computatio…