IRONSOFTWAREHOME

How to Detect Page Rotation in C# with IronOCR

Curtis Chau
Curtis Chau
Updated: August 26, 2026

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.

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2Copy and run this code snippet.

    var rotationResults = new IronOcr.OcrInput().LoadPdf("doc.pdf").DetectPageOrientation();
    Console.WriteLine(rotationResults.First().RotationAngle);
    C#
  3. 3Deploy 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 note: This function performs best with text-dense documents.
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);
}

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°
}

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 optional parameters to control detection detail and resource use. By providing an OrientationDetectionMode enum, you can adjust detection speed and accuracy based on your requirements, and a second maxDegreeOfParallelism argument bounds how many pages are analysed at the same time.

Here's how to implement it:

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);
}

Which Detection Mode Should I Choose?

Four speed options are available for OrientationDetectionMode:

Warning: Balanced, 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, and reuses one engine per worker thread rather than allocating one per page, keeping memory use low on long documents.
  • 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.

How Do I Bound Memory During Orientation Detection?

On multi-page inputs, orientation detection analyses several pages at once, and each concurrent page uses its own native engine. Pass a maxDegreeOfParallelism value to cap that concurrency and hold peak memory down - useful on memory-constrained servers and containers, and mirroring the MaxDegreeOfParallelism control available when reading documents in parallel.

using IronOcr;
using System.Collections.Generic;

using var input = new OcrInput();
input.LoadPdf("scanned.pdf");

// Cap orientation detection to 2 pages at a time. The default is one per CPU core.
IEnumerable<OcrPageOrientationResult> orientation =
    input.DetectPageOrientation(OrientationDetectionMode.Fast, maxDegreeOfParallelism: 2);
C#
Please note: A non-positive value falls back to Environment.ProcessorCount. The single-argument DetectPageOrientation overload is unchanged and remains fully supported, so existing code continues to work without modification.

What Are Common Performance Considerations?

Performance varies significantly between modes. Fast mode is optimized for high-throughput processing, while ExtremeDetailed prioritizes accuracy at the cost of speed. 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, and pass a maxDegreeOfParallelism value to cap how many pages are analysed at once. 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. Bound it with MaxDegreeOfParallelism when memory is constrained.

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)
    {
        // Load the specific page as its own input and correct it
        using var pageInput = new OcrInput();
        pageInput.LoadPdfPage("doc.pdf", i);
        pageInput.Rotate(360 - pageResult.RotationAngle);
    }
}
C#

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

How does IronOCR detect page rotation?

IronOCR uses the `DetectPageOrientation` method to automatically identify the rotation angle of pages in PDFs and images, detecting orientations of 0°, 90°, 180°, and 270° to ensure accurate text extraction.

What is the purpose of the RotationAngle property in IronOCR?

The `RotationAngle` property in IronOCR is used to indicate the degree of rotation detected for each page. This allows developers to programmatically correct the orientation of the pages for precise text rendering and extraction.

Can IronOCR handle non-standard page rotations?

Yes, for skewed images beyond the standard 0°, 90°, 180°, and 270° rotations, IronOCR suggests using the `Deskew` method from its image correction filters, allowing the image to be properly oriented.

What is the HighConfidence property in IronOCR?

The `HighConfidence` property in IronOCR reflects the confidence level of the detected orientation. It is especially useful for documents with ambiguous or low-quality scans, where more validation might be required.

How can IronOCR improve detection speed and accuracy?

IronOCR provides an optional `OrientationDetectionMode` parameter for `DetectPageOrientation`, allowing users to adjust the detection speed and accuracy, ranging from Fast to ExtremeDetailed modes based on the user's needs.

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.

How do I limit memory usage when detecting orientation on large PDFs?

Pass a maxDegreeOfParallelism value to the DetectPageOrientation overload, for example input.DetectPageOrientation(OrientationDetectionMode.Fast, maxDegreeOfParallelism: 2). This caps how many pages are analysed at the same time, and because each concurrent page uses its own native engine, it directly caps peak memory. A non-positive value falls back to Environment.ProcessorCount.

Does adding the maxDegreeOfParallelism parameter break existing code?

No. The single-argument DetectPageOrientation overload is unchanged and remains fully supported, so existing code continues to work without modification. In Fast mode, orientation detection is also more memory efficient because it reuses one engine per worker thread rather than allocating one per page, and results are unchanged.

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

Ready to Get Started?

Nuget Downloads 6,236,385Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required