using IronOcr;using System;using var input = new OcrInput();// Load PDF documentinput.LoadPdf("Clockwise90.pdf");// Detect page rotationvar results = input.DetectPageOrientation();// Ouput resultforeach(var result in results){Console.WriteLine(result.PageNumber);Console.WriteLine(result.HighConfidence);Console.WriteLine(result.RotationAngle);}
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);
}
ImportsIronOcrImportsSystemPrivate input = New OcrInput()' Load PDF documentinput.LoadPdf("Clockwise90.pdf")' Detect page rotationDim results = input.DetectPageOrientation()' Ouput resultFor Each result In resultsConsole.WriteLine(result.PageNumber)Console.WriteLine(result.HighConfidence)Console.WriteLine(result.RotationAngle)Next result
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
// Apply rotation correction based on detection resultsif (result.RotationAngle != 0){ input.Rotate(360 - result.RotationAngle); // Rotate back to 0°}
// Apply rotation correction based on detection results
if (result.RotationAngle != 0)
{
input.Rotate(360 - result.RotationAngle); // Rotate back to 0°
}
' Apply rotation correction based on detection resultsIf result.RotationAngle <> 0 Then input.Rotate(360 - result.RotationAngle) ' Rotate back to 0°End If
' Apply rotation correction based on detection results
If result.RotationAngle <> 0 Then
input.Rotate(360 - result.RotationAngle) ' Rotate back to 0°
End If
using IronOcr;using System;using var input = new OcrInput();// Load PDF documentinput.LoadPdf("Clockwise90.pdf");// Detect page rotation with Fast modevar results = input.DetectPageOrientation(OrientationDetectionMode.Fast);// Ouput resultforeach(var result in results){Console.WriteLine(result.PageNumber);Console.WriteLine(result.HighConfidence);Console.WriteLine(result.RotationAngle);}
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);
}
ImportsIronOcrImportsSystemUsing input As New OcrInput() ' Load PDF document input.LoadPdf("Clockwise90.pdf") ' Detect page rotation with Fast mode Dim results = input.DetectPageOrientation(OrientationDetectionMode.Fast) ' Output result For Each result In resultsConsole.WriteLine(result.PageNumber)Console.WriteLine(result.HighConfidence)Console.WriteLine(result.RotationAngle) NextEndUsing
Imports IronOcr
Imports System
Using input As New OcrInput()
' Load PDF document
input.LoadPdf("Clockwise90.pdf")
' Detect page rotation with Fast mode
Dim results = input.DetectPageOrientation(OrientationDetectionMode.Fast)
' Output result
For Each result In results
Console.WriteLine(result.PageNumber)
Console.WriteLine(result.HighConfidence)
Console.WriteLine(result.RotationAngle)
Next
End Using
// Process each page with individual rotation detectionfor (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) { // Correct the specific page input.Pages[i].Rotate(360 - pageResult.RotationAngle); }}
// 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)
{
// Correct the specific page
input.Pages[i].Rotate(360 - pageResult.RotationAngle);
}
}
' Process each page with individual rotation detectionFor i AsInteger = 0 To results.Count - 1 Dim pageResult = results(i) ' Apply rotation only to pages that need it If pageResult.RotationAngle <> 0AndAlso pageResult.HighConfidenceThen ' Correct the specific page input.Pages(i).Rotate(360 - pageResult.RotationAngle) End IfNext
' Process each page with individual rotation detection
For i As Integer = 0 To results.Count - 1
Dim pageResult = results(i)
' Apply rotation only to pages that need it
If pageResult.RotationAngle <> 0 AndAlso pageResult.HighConfidence Then
' Correct the specific page
input.Pages(i).Rotate(360 - pageResult.RotationAngle)
End If
Next
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.