[Public] Understanding Page Orientation and Rotation in PDFs
How IronOCR and IronPDF works in determining the Orientation and Rotation of a PDF document
When working with PDFs, it's often necessary to determine the orientation (portrait or landscape) of a page and whether the content is rotated. Our SDK provides two main approaches for this:
-
PdfDocument.Pages[i].PageRotation
– metadata-based rotation -
OcrInput.DetectPageOrientation()
– OCR-based orientation detection
This article explains the difference between the two and how to use them effectively.
Understanding Orientation vs. Rotation
-
Page orientation refers to the page layout:
-
Portrait (height > width)
-
Landscape (width > height)
-
-
Rotation angle refers to how the content on the page is rotated relative to the natural reading direction (e.g., 90°, 180°, etc.)
Using IronPdf.PdfDocument.PageRotation
IronPDF returns the PageRotation value by reading the rotation metadata that is embedded in the PDF file. It tells you how the content is programmatically rotated, which is reliable and consistent if the PDF is well-formed.
Example
This approach gives you both:
-
Page orientation (based on width/height)
-
Rotation angle (from PDF metadata)
Best for: Structured PDFs with consistent metadata
Using OcrInput.DetectPageOrientation()
IronOCR detects orientation of a PDF page by analyzing the visual layout of each page using OCR and infers the likely reading direction. It does not rely on metadata.
Example
This is useful for:
-
Scanned documents
-
Image-based PDFs
-
Files without proper metadata
Note: The accuracy depends heavily on text density and clarity. Sparse or misaligned text may cause incorrect detection. To avoid this, use Rectangle and do OCR on area that have denser text to avoid wrong orientation returned.
Recommendation
-
Use
PdfDocument.PageRotation
when working with digital PDFs that have correct metadata. -
Use
OcrInput.DetectPageOrientation()
for scanned or image-based PDFs where metadata is missing or unreliable. -
For best results, consider using both methods and applying custom logic to resolve discrepancies in critical workflows.
Summary
Method | Source | Best For | Caveats |
---|---|---|---|
PdfDocument.PageRotation |
PDF Metadata | Digitally generated PDFs | Requires valid metadata |
OcrInput.DetectPageOrientation() |
Visual OCR Analysis | Scanned/image-based PDFs | May be inaccurate on sparse/misaligned text |
If you're seeing inconsistent rotation results, we recommend checking the specific page layout and using both methods together for validation.