How to Detect Page Rotation
Determining page rotation involves identifying the degree of rotation applied to a page within a document. This process specifically determine 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.
How to Detect Page Rotation
- Download a C# library to detect page rotation
- Import the PDF document and images for reading
- Use the
DetectPageOrientation
method to detect rotation for all pages - Access the RotationAngle property to correct page rotation
- Access the HighConfidence property to handle edge cases
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 note
: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
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 theRotate
method asinput.Rotate(RotationAngle)
. - HighConfidence: Indicates the level of confidence in the orientation result.