Cómo detectar rotación de página para OCR en C# | IronOCR

How to Detect Page Rotation

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Quickstart: Use DetectPageOrientation to Identify Page Rotation

In this quick example, developers use IronOCR’s DetectPageOrientation on a loaded PDF and immediately access the most confident page’s RotationAngle. It’s a fast way to detect and correct page rotation with minimal setup and 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


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.

Por favor notaThis 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. Furthermore, this information can be used with the Rotate method to return the image to its upright orientation.
  • 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:

AdvertenciaUsing 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.

Preguntas Frecuentes

¿Cómo puedo detectar la rotación de página en un documento usando C#?

Puede usar el método DetectPageOrientation de IronOCR para identificar la rotación de páginas en un documento. Este método puede detectar rotaciones en ángulos de 0, 90, 180 y 270 grados.

¿Qué pasos están involucrados en corregir la rotación de páginas en IronOCR?

Primero, use el método DetectPageOrientation para determinar el ángulo de rotación. Luego, aplique el método Rotate con la propiedad RotationAngle para corregir la orientación de la página.

¿Cómo maneja IronOCR las imágenes de documentos sesgadas?

Para imágenes sesgadas, IronOCR ofrece un método Deskew para corregir la distorsión antes de aplicar correcciones de rotación.

¿Qué propiedades ayudan a asegurar una detección precisa de la rotación de página?

La propiedad RotationAngle indica el ángulo necesario para la corrección, mientras que la propiedad HighConfidence muestra el nivel de confianza en la orientación detectada, ayudando a manejar casos límite.

¿Cómo puedo asegurarme de que las páginas de mi documento se muestren correctamente utilizando IronOCR?

Use el método DetectPageOrientation para encontrar el ángulo de rotación y aplique el método Rotate usando este ángulo para corregir la orientación de la página.

¿Puede IronOCR manejar documentos con mucho texto de manera efectiva?

Sí, la función DetectPageOrientation de IronOCR está diseñada para funcionar bien incluso con documentos con mucho texto.

¿Qué indica la propiedad PageNumber en IronOCR?

La propiedad PageNumber indica el índice basado en cero de la página que se está procesando, ayudando a rastrear las correcciones de orientación en múltiples páginas.

¿Cómo corrijo un documento que está tanto rotado como sesgado?

Primero, use el método Deskew de IronOCR para corregir cualquier distorsión, luego aplique el método DetectPageOrientation seguido por el método Rotate usando el RotationAngle detectado para corregir cualquier rotación.

¿Cuál es la importancia de detectar la rotación de páginas en el procesamiento de documentos?

Detectar la rotación de páginas asegura que los documentos se representen y procesen con precisión, manteniendo las orientaciones correctas para su visualización o impresión, lo cual es crítico para aplicaciones como el OCR.

¿Puede IronOCR manejar documentos con múltiples ángulos de rotación en un solo documento?

Sí, IronOCR puede detectar y corregir diferentes ángulos de rotación para cada página en un documento utilizando el método DetectPageOrientation.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
Revisado por
Jeff Fritz
Jeffrey T. Fritz
Gerente Principal de Programas - Equipo de la Comunidad .NET
Jeff también es Gerente Principal de Programas para los equipos de .NET y Visual Studio. Es el productor ejecutivo de la serie de conferencias virtuales .NET Conf y anfitrión de 'Fritz and Friends', una transmisión en vivo para desarrolladores que se emite dos veces a la semana donde habla sobre tecnología y escribe código junto con la audiencia. Jeff escribe talleres, presentaciones, y planifica contenido para los eventos de desarrolladores más importantes de Microsoft, incluyendo Microsoft Build, Microsoft Ignite, .NET Conf y la Cumbre de Microsoft MVP.
¿Listo para empezar?
Nuget Descargas 5,044,537 | Versión: 2025.11 recién lanzado