Page Orientation vs. Rotation Detection

Curtis Chau
Curtis Chau
Updated: November 12, 2026

Determining whether a PDF page is portrait or landscape, and whether its content is rotated, can be done two ways in the SDK. The right choice depends on whether the file carries reliable metadata.

PdfDocument.Pages[i].PageRotation reads rotation metadata embedded in the PDF. OcrInput.DetectPageOrientation() detects orientation by analyzing the visual layout with OCR.

Orientation vs. Rotation

These are two different measurements:

  • Page orientation: the page layout, either Portrait (height greater than width) or Landscape (width greater than height).
  • Rotation angle: how the content on the page is rotated relative to the natural reading direction, such as 90 degrees or 180 degrees.

Option 1: Read Metadata with PageRotation

IronPDF returns the PageRotation value by reading the rotation metadata embedded in the PDF file. It reports how the content is programmatically rotated, which stays reliable and consistent when the PDF is well-formed.

var pdf = PdfDocument.FromFile("sample.pdf");
for (int i = 0; i < pdf.PageCount; i++)
{
    var page = pdf.Pages[i];
    var orientation = page.Width > page.Height ? "Landscape" : "Portrait";
    var rotation = page.PageRotation;
    Console.WriteLine($"Page {i + 1}: {orientation}, Rotation: {rotation} degrees");
}

This gives you orientation from the width/height comparison and the rotation angle from the PDF metadata in one pass.

Best for: structured PDFs with consistent metadata.

Option 2: Detect Visually with DetectPageOrientation()

IronOCR detects the orientation of a PDF page by analyzing the visual layout of each page with OCR and inferring the likely reading direction. It does not rely on metadata at all.

using var input = new OcrInput();
input.LoadPdf("sample.pdf");
var results = input.DetectPageOrientation();
foreach (var result in results)
{
    Console.WriteLine($"Page {result.PageNumber + 1}: Rotation: {result.RotationAngle} degrees");
}

Reach for this with scanned documents, image-based PDFs, and files that lack proper metadata.

Accuracy depends heavily on text density and clarity. Sparse or misaligned text can produce incorrect detection. To work around this, pass a Rectangle and run OCR on an area with denser text so the orientation result stays correct.

Please note: From v2026.11.1, a page whose small vertical text such as captions outweighs the larger body text is no longer reported as rotated when it is upright, and the confidence reporting better indicates whether the detected orientation is reliable.

Recommendation

Pick the method that matches your source material:

  • Use PdfDocument.PageRotation for digital PDFs that carry correct metadata.
  • Use OcrInput.DetectPageOrientation() for scanned or image-based PDFs where metadata is missing or unreliable.

For critical workflows, run both methods and apply custom logic to resolve any discrepancies. If you see inconsistent rotation results, check the specific page layout and validate with both methods together.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

Read More

Ready to Get Started?

NuGet Downloads 6,411,693Version:2026.11just released