How to Detect Page Rotation for OCR in C# | IronOCR

How to Detect Page Rotation in C# with IronOCR

IronOCR's DetectPageOrientation method automatically identifies page rotation angles (0°, 90°, 180°, 270°) in PDF documents and images. It returns a RotationAngle property for each page, enabling programmatic orientation correction with confidence scores for accurate text extraction.

Page rotation detection identifies whether a document page has been rotated clockwise or counterclockwise by 0, 90, 180, or 270 degrees. This information ensures pages are displayed or processed in their correct orientation for accurate rendering and text extraction.

Quickstart: Use DetectPageOrientation to Identify Page Rotation

This example demonstrates using IronOCR's DetectPageOrientation on a PDF to access the RotationAngle property. It provides fast page rotation detection and correction with minimal code.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    var rotationResults = new IronOcr.OcrInput().LoadPdf("doc.pdf").DetectPageOrientation();
    Console.WriteLine(rotationResults.First().RotationAngle);
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer


How Do I Detect Page Rotation in My Documents?

After loading a document, use the DetectPageOrientation method to identify each page's rotation. This method supports 0, 90, 180, and 270 degrees. For skewed images beyond these standard rotations, use the Deskew method from IronOCR's image correction filters. Then rotate the image back to its original orientation using the detected angle. Let's work with a sample PDF.

Please noteThis function performs best with text-dense documents.

:path=/static-assets/ocr/content-code-examples/how-to/detect-page-rotation-detect-page-rotation.cs
using IronOcr;
using System;

using var input = new OcrInput();

// Load PDF document
input.LoadPdf("Clockwise90.pdf");

// Detect page rotation
var results = input.DetectPageOrientation();

// Ouput result
foreach(var result in results)
{
    Console.WriteLine(result.PageNumber);
    Console.WriteLine(result.HighConfidence);
    Console.WriteLine(result.RotationAngle);
}
Imports IronOcr
Imports System

Private input = New OcrInput()

' Load PDF document
input.LoadPdf("Clockwise90.pdf")

' Detect page rotation
Dim results = input.DetectPageOrientation()

' Ouput result
For Each result In results
	Console.WriteLine(result.PageNumber)
	Console.WriteLine(result.HighConfidence)
	Console.WriteLine(result.RotationAngle)
Next result
$vbLabelText   $csharpLabel

What Do the Detection Results Mean?

  • PageNumber: Zero-based index of the page.
  • RotationAngle: Rotation angle in degrees. Use with the Rotate method to correct orientation.
  • HighConfidence: Confidence level in the orientation result for handling edge cases.

When Should I Use High Confidence Values?

The HighConfidence property is crucial for ambiguous or low-quality documents where rotation detection may be uncertain. Documents with sparse text, unusual layouts, or poor scan quality often return lower confidence scores. In these cases, implement additional validation or apply image quality correction filters before detection.

Use this value to implement fallback strategies or manual review for pages with low confidence. For instance, if confidence falls below 80%, process the page with multiple orientations and compare OCR results, or flag for manual review. IronOCR's computer vision features help identify text regions more accurately in challenging documents.

How Do I Correct Detected Rotation?

After identifying the rotation angle, use the Rotate method on your OcrInput object to correct orientation before OCR. This ensures optimal text recognition accuracy. For comprehensive orientation fixes, see the image orientation correction guide. Here's the correction process:

// Apply rotation correction based on detection results
if (result.RotationAngle != 0)
{
    input.Rotate(360 - result.RotationAngle); // Rotate back to 0°
}
// Apply rotation correction based on detection results
if (result.RotationAngle != 0)
{
    input.Rotate(360 - result.RotationAngle); // Rotate back to 0°
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

For documents requiring additional preprocessing, consider the OcrInput Class which provides extensive document preparation methods before OCR processing.

How Can I Customize Detection Speed and Accuracy?

The DetectPageOrientation method accepts an optional parameter to control detection detail. By providing OrientationDetectionMode enums, you can adjust detection speed and accuracy based on your requirements.

Here's how to implement it:

:path=/static-assets/ocr/content-code-examples/how-to/detect-page-rotation-detect-page-rotation-advanced.cs
using IronOcr;
using System;

using var input = new OcrInput();

// Load PDF document
input.LoadPdf("Clockwise90.pdf");

// Detect page rotation with Fast mode
var results = input.DetectPageOrientation(OrientationDetectionMode.Fast);

// Ouput result
foreach(var result in results)
{
    Console.WriteLine(result.PageNumber);
    Console.WriteLine(result.HighConfidence);
    Console.WriteLine(result.RotationAngle);
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Which Detection Mode Should I Choose?

Four speed options are available for OrientationDetectionMode:

WarningBalanced, Detailed, and ExtremeDetailed require the IronOcr.Extensions.AdvancedScan package. These options are unavailable on Windows x86 and Mac ARM.

  • Fast: High-speed detection with lower accuracy. Ideal for drafts or bulk processing where speed is crucial. Default for DetectPageOrientation. Handles thousands of pages efficiently with multithreading support.

  • Balanced: Balanced speed and accuracy. Suitable for production tasks. Uses AdvancedScan extension capabilities for improved accuracy while maintaining performance.

  • Detailed: Low speed, high accuracy. Best for precise or critical tasks, especially documents with complex layouts or mixed content.

  • ExtremeDetailed: Slowest speed, highest accuracy. Use only when Detailed is insufficient or text is heavily skewed and distorted.

What Are Common Performance Considerations?

Performance varies significantly between modes. Fast mode processes hundreds of pages per minute; ExtremeDetailed may take seconds per page. Choose based on accuracy requirements and time constraints. For optimal performance:

  1. Image Resolution: Higher DPI settings improve accuracy but increase processing time. 150-300 DPI typically suffices for rotation detection.

  2. Document Type: Text-dense documents process faster and more accurately than sparse layouts. Use the Filter Wizard to optimize image quality before detection.

  3. Resource Usage: Monitor memory usage when processing large batches. Implement progress tracking to provide feedback and manage system resources.

  4. Parallel Processing: For bulk operations, use IronOCR's multithreading to process multiple documents simultaneously while maintaining accuracy.

How Do I Handle Mixed-Orientation Documents?

For mixed-orientation documents, process each page individually with DetectPageOrientation, then apply page-by-page rotation corrections before OCR. This ensures proper orientation regardless of initial state. Here's an effective approach:

// Process each page with individual rotation detection
for (int i = 0; i < results.Count; i++)
{
    var pageResult = results[i];

    // Apply rotation only to pages that need it
    if (pageResult.RotationAngle != 0 && pageResult.HighConfidence)
    {
        // Correct the specific page
        input.Pages[i].Rotate(360 - pageResult.RotationAngle);
    }
}
// Process each page with individual rotation detection
for (int i = 0; i < results.Count; i++)
{
    var pageResult = results[i];

    // Apply rotation only to pages that need it
    if (pageResult.RotationAngle != 0 && pageResult.HighConfidence)
    {
        // Correct the specific page
        input.Pages[i].Rotate(360 - pageResult.RotationAngle);
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

For complex scenarios involving scanned documents with varying quality or multi-page TIFFs, preprocess each page individually for optimal results.

When processing mixed-format inputs, the OcrResult Class provides detailed page information, enabling sophisticated error handling and quality control workflows. For high-throughput production environments, explore Fast OCR Configuration options to balance speed and accuracy.

If processing documents containing both text and barcodes, use IronOCR's OCR with Barcode & QR Reading capabilities to extract all information in a single pass, improving efficiency.

Frequently Asked Questions

What is page rotation detection and why is it important?

Page rotation detection identifies whether a document page has been rotated by 0°, 90°, 180°, or 270° degrees. This is crucial for IronOCR to ensure pages are processed in their correct orientation, enabling accurate text extraction and rendering from PDFs and images.

How do I quickly detect page rotation in a PDF using C#?

Use IronOCR's DetectPageOrientation method with minimal code: var rotationResults = new IronOcr.OcrInput().LoadPdf("doc.pdf").DetectPageOrientation(); This returns rotation information for all pages, accessible through the RotationAngle property.

What rotation angles can be detected?

IronOCR's DetectPageOrientation method can detect standard rotations of 0°, 90°, 180°, and 270° degrees. For skewed images beyond these standard rotations, use IronOCR's Deskew method from the image correction filters.

What information does DetectPageOrientation return?

The method returns three key properties for each page: PageNumber (zero-based index), RotationAngle (rotation in degrees for use with IronOCR's Rotate method), and HighConfidence (confidence level for handling edge cases).

When should I use the HighConfidence property?

Use the HighConfidence property when working with ambiguous or low-quality documents where rotation detection may be uncertain. Documents with sparse text, unusual layouts, or poor scan quality often return lower confidence scores in IronOCR, requiring additional validation or image quality correction filters.

Does this feature work best with certain types of documents?

IronOCR's DetectPageOrientation function performs best with text-dense documents. For documents with minimal text or complex layouts, consider applying image quality correction filters before detection for optimal results.

Curtis Chau
Technical Writer

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
Reviewed by
Jeff Fritz
Jeffrey T. Fritz
Principal Program Manager - .NET Community Team
Jeff is also a Principal Program Manager for the .NET and Visual Studio teams. He is the executive producer of the .NET Conf virtual conference series and hosts 'Fritz and Friends' a live stream for developers that airs twice weekly where he talks tech and writes code together with viewers. Jeff writes workshops, presentations, and plans content for the largest Microsoft developer events including Microsoft Build, Microsoft Ignite, .NET Conf, and the Microsoft MVP Summit
Ready to Get Started?
Nuget Downloads 5,219,969 | Version: 2025.12 just released