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.

[i:{(This 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;

// Create an instance of OcrInput to manage OCR-related operations.
using var input = new OcrInput();

// Load a PDF document from a specified path.
// The method LoadPdf loads the document into the OcrInput instance for further processing.
input.AddPdf("Clockwise90.pdf");

// DetectPageOrientation analyzes the document to detect the rotation of each page.
// This is useful for correcting documents that might have been scanned at incorrect angles.
var results = input.DetectPageOrientation();

// Output the results to the console.
// Iterate over each detected page orientation result.
foreach (var result in results)
{
    // Output the page number to the console.
    Console.WriteLine($"Page Number: {result.PageNumber}");
    // Output the confidence level that the detected rotation is correct.
    Console.WriteLine($"High Confidence: {result.HighConfidence}");
    // Output the detected rotation angle for the page.
    Console.WriteLine($"Rotation Angle: {result.RotationAngle}");
}
Imports IronOcr
Imports System

' Create an instance of OcrInput to manage OCR-related operations.
Private input = New OcrInput()

' Load a PDF document from a specified path.
' The method LoadPdf loads the document into the OcrInput instance for further processing.
input.AddPdf("Clockwise90.pdf")

' DetectPageOrientation analyzes the document to detect the rotation of each page.
' This is useful for correcting documents that might have been scanned at incorrect angles.
Dim results = input.DetectPageOrientation()

' Output the results to the console.
' Iterate over each detected page orientation result.
For Each result In results
	' Output the page number to the console.
	Console.WriteLine($"Page Number: {result.PageNumber}")
	' Output the confidence level that the detected rotation is correct.
	Console.WriteLine($"High Confidence: {result.HighConfidence}")
	' Output the detected rotation angle for the page.
	Console.WriteLine($"Rotation Angle: {result.RotationAngle}")
Next result
$vbLabelText   $csharpLabel

Understanding the Result

  • PageNumber: Indicates the zero-based index of the page.
  • RotationAngle: Provides the corrective rotation angle in degrees. This angle can be applied to the Rotate method to return the image to right-side-up rotation. For example, if the image is rotated 90 degrees clockwise, the angle returned will be 270, which can then be passed to the Rotate method as input.Rotate(RotationAngle).
  • HighConfidence: Indicates the level of confidence in the orientation result, which helps in handling edge cases more effectively.

Frequently Asked Questions

What is page rotation detection?

Page rotation detection involves identifying the degree to which a page within a document has been rotated, ensuring that pages are displayed or processed in their correct orientations.

Which angles can IronOCR detect for page rotation?

IronOCR can detect page rotations at angles of 0, 90, 180, and 270 degrees.

How can I correct the page rotation using IronOCR?

After detecting the page rotation using the `DetectPageOrientation` method, you can use the `Rotate` method with the returned `RotationAngle` to adjust the image to the correct orientation.

What is the `HighConfidence` property used for?

The `HighConfidence` property indicates the level of confidence in the orientation result, helping to handle edge cases more effectively.

What should I do if the document is skewed?

If the document is skewed, you can use the `Deskew` image correction method provided by IronOCR to correct it.

Is IronOCR suitable for text-dense documents?

Yes, the `DetectPageOrientation` function in IronOCR performs well with text-dense documents.

How do I access the rotation angle for a page?

The rotation angle for a page can be accessed via the `RotationAngle` property after running the `DetectPageOrientation` method on the document.

What is the first step to detect page rotation using IronOCR?

The first step is to download a C# library that includes IronOCR to detect page rotation.

How is the page number indicated in the result?

The page number is indicated by the `PageNumber` property, which shows the zero-based index of the page.

Can IronOCR handle rotated document images?

Yes, IronOCR can detect and handle rotated document images, allowing you to correct their orientation using the detected rotation angle.

Chaknith related to Understanding the Result
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.