How to Detect Page Rotation

Determining page rotation involves identifying the degree of rotation applied to a page within a document. This process specifically determines if the page has been rotated clockwise or counterclockwise by angles of 0, 90, 180, and 270 degrees. This information is crucial for rendering or processing the document accurately, ensuring that pages are displayed or printed in their correct orientations.

IronOCR takes page rotation detection to the next level. Once rotation has been detected, the returned value can be used in combination with the Rotate method to adjust the image to the correct orientation.

Get started with IronOCR

Start using IronOCR in your project today with a free trial.

First Step:
green arrow pointer



Detect Page Rotation Example

After loading the document, you can utilize the DetectPageOrientation method to identify the rotation of each page. This method supports degrees of 0, 90, 180, and 270. For skewed images, the Deskew image correction method can be used. Subsequently, rotate the image back to its original orientation using the degree returned from the function. Let's proceed with a sample PDF.

Please noteThis function performs well when the document is text-dense.

: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

Understanding the Result

  • PageNumber: Indicates the zero-based index of the page.
  • RotationAngle: Provides the rotation angle in degrees. This angle can be used with the Rotate method to return the image to its upright orientation. For example, if an image is rotated 90 degrees clockwise, you would pass an angle of 270 (calculated as 360 - 90) to the Rotate method to straighten it.
  • HighConfidence: Indicates the level of confidence in the orientation result, which helps in handling edge cases more effectively.

Advanced Detect Page Rotation

The DetectPageOrientation method also allows you to provide an optional parameter that controls the level of detail in the detection. By providing OreitnationDetectioMode enums as a parameter, users can customize and adjust the detecting speed and details based on their needs.

Here's a quick code example on how to use 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

There are currently four speed options available for OrientationDetectionMode:

WarningUsing Balanced, Detailed and ExtremeDetailed options requires you to install the IronOcr.Extensions.AdvancedScan package. These options cannot be used on Windows x86 and Mac ARM at this time.

  • Fast: The Fast orientation mode detects the orientation angle at high speed but with low accuracy; as such, it is more ideal for draft or bulk processing where speed is crucial. This is the default setting for the DetectPageOrientation method.

  • Balanced: The Balanced orientation mode determines the orientation angle with balanced speed and accuracy; it is generally more suited for default or production tasks.

  • Detailed: The Detailed orientation mode determines the orientation angle with low speed but high accuracy; as such, it is generally more suited for precise or critical tasks.

  • ExtremeDetailed: The ExtremeDetailed orientation mode determines the orientation angle with the slowest speed but provides the highest accuracy possible. However, the slower speed compared to other options makes it ideal only when the Detailed option isn't sufficient or the text input itself is heavily skewed and distorted.

Frequently Asked Questions

How can I detect page rotation in a document using C#?

You can use IronOCR's DetectPageOrientation method to identify the rotation of pages in a document. This method can detect rotations at angles of 0, 90, 180, and 270 degrees.

What steps are involved in correcting page rotation in IronOCR?

First, use the DetectPageOrientation method to determine the rotation angle. Then, apply the Rotate method with the RotationAngle property to correct the page's orientation.

How does IronOCR handle skewed document images?

For skewed images, IronOCR provides a Deskew method to correct the skew before applying rotation corrections.

What properties help ensure accurate page rotation detection?

The RotationAngle property indicates the angle needed for correction, while the HighConfidence property shows the confidence level in the detected orientation, helping manage edge cases.

How can I ensure my document pages are displayed correctly using IronOCR?

Use the DetectPageOrientation method to find the rotation angle and apply the Rotate method using this angle to correct the page orientation.

Can IronOCR handle text-dense documents effectively?

Yes, IronOCR's DetectPageOrientation function is designed to perform well even with text-dense documents.

What does the PageNumber property indicate in IronOCR?

The PageNumber property indicates the zero-based index of the page being processed, helping track orientation corrections across multiple pages.

How do I correct a document that is both rotated and skewed?

First, use IronOCR's Deskew method to correct any skew, then apply the DetectPageOrientation method followed by the Rotate method using the detected RotationAngle to correct any rotation.

What is the importance of detecting page rotation in document processing?

Detecting page rotation ensures documents are rendered and processed accurately, maintaining correct orientations for display or printing, which is critical for applications like OCR.

Can IronOCR handle documents with multiple rotation angles in a single document?

Yes, IronOCR can detect and correct different rotation angles for each page in a document using the DetectPageOrientation method.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
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 4,524,161 | Version: 2025.9 just released