Anbaugebiete und Rechtecke mit IronOCR
Wie lege ich Inhaltsbereiche in PDFs mit IronOCR fest?
Inhaltsbereiche und PDFs
OcrInput.LoadPdf und LoadPdfPage Methoden haben alle die Option, einen ContentArea hinzuzufügen.
Die Frage - Wie weiß ich, wie groß mein Inhaltsbereich ist, da PDFs nicht in Pixeln dimensioniert sind, sondern Inhaltsbereiche allgemein in ihnen gemessen werden?
Option 1
OcrInput.TargetDPI Standardwert ist 225 - dies bestimmt die Größe des PDF-Bildes in Pixel. IronOCR wird dies lesen.
Option 2 (idealer Anwendungsfall)
- Verwenden Sie
OcrInput.LoadPdf()mit Ihrer PDF-Vorlage. - Verwenden Sie
OcrInput.GetPages(), um die Breite und Höhe der Eingabe zu erhalten. - Verwenden Sie
OcrInput.GetPages().First().ToBitmap(), um das genaue Bild zu erhalten, das die OCR-Engine lesen wird. - Sie können nun Inhaltbereiche in Pixeln vom exportierten Bild messen.
- Die angepeilten Koordinaten könnten für einen bestimmten OCR-Bereich verwendet werden (siehe im Endergebnis).
Um deine Informationen zu erhalten:
using System.Linq; // Needed for First()
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Load the PDF document
input.LoadPdf("example.pdf");
// Save the first page as a bitmap to measure it
input.GetPages().First().ToBitmap().SaveAs("measure-me.bmp");
// Get the dimensions of the first page
var width = input.GetPages().First().Width;
var height = input.GetPages().First().Height;
// Optionally, output the dimensions to understand the scale
Console.WriteLine($"Width: {width}px, Height: {height}px");
}Imports System.Linq ' Needed for First()
Imports IronOcr
Dim ocr As New IronTesseract()
Using input As New OcrInput()
' Load the PDF document
input.LoadPdf("example.pdf")
' Save the first page as a bitmap to measure it
input.GetPages().First().ToBitmap().SaveAs("measure-me.bmp")
' Get the dimensions of the first page
Dim width = input.GetPages().First().Width
Dim height = input.GetPages().First().Height
' Optionally, output the dimensions to understand the scale
Console.WriteLine($"Width: {width}px, Height: {height}px")
End UsingEndergebnis:
using IronOcr;
using IronSoftware.Drawing; // Needed for Rectangle
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Define the content area rectangle with specific pixel coordinates
var contentArea = new Rectangle
{
X = 215,
Y = 1250,
Height = 280,
Width = 1335
}; //<-- the area you want in px
// Load the specific content area of the PDF
input.LoadPdf("example.pdf", contentArea: contentArea);
// Perform OCR on the defined content area
var result = ocr.Read(input);
// Optionally, print the OCR result
Console.WriteLine(result.Text);
}Imports IronOcr
Imports IronSoftware.Drawing ' Needed for Rectangle
Dim ocr As New IronTesseract()
Using input As New OcrInput()
' Define the content area rectangle with specific pixel coordinates
Dim contentArea As New Rectangle With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
} '<-- the area you want in px
' Load the specific content area of the PDF
input.LoadPdf("example.pdf", contentArea:=contentArea)
' Perform OCR on the defined content area
Dim result = ocr.Read(input)
' Optionally, print the OCR result
Console.WriteLine(result.Text)
End UsingAPI-Referenz: OcrInput|OcrInput.Page

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender Handbücher.