PDF 內容區域與裁剪區域
如何使用 IronOCR 設定 PDF 的內容區域?
ContentAreas 和 PDFs
OcrInput.LoadPdf
和 LoadPdfPage
方法都可以選擇添加一個 ContentArea。
問題 - 我怎麼知道我的內容區域有多大,因為 PDF 並不是以像素為單位大小,但內容區域通常是以像素來測量的?
選項 1
OcrInput.TargetDPI 預設為 225 - 決定 PDF 圖片的像素大小。IronOCR 將會讀取這個值。
選項 2 (理想使用案例)
使用 OcrInput.LoadPdf() 與您的PDF模板一起
使用 OcrInput.GetPages() 獲取輸入的寬度和高度
使用 OcrInput.GetPages().First().ToBitmap() 以獲取OCR引擎將讀取的確切圖像
您現在可以從匯出圖像中以像素為單位測量內容區域
- 目標坐標可用於特定的OCR區域 (查看最終結果)
取得您的資訊:
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
input.LoadPdf("example.pdf");
input.GetPages().First().ToBitmap().SaveAs("measure-me.bmp");
var width = input.GetPages().First().Width;
var height = input.GetPages().First().Height;
}
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
input.LoadPdf("example.pdf");
input.GetPages().First().ToBitmap().SaveAs("measure-me.bmp");
var width = input.GetPages().First().Width;
var height = input.GetPages().First().Height;
}
Imports IronOcr
Private ocr = New IronTesseract()
Using input = New OcrInput()
input.LoadPdf("example.pdf")
input.GetPages().First().ToBitmap().SaveAs("measure-me.bmp")
Dim width = input.GetPages().First().Width
Dim height = input.GetPages().First().Height
End Using
最終結果:
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
var contentArea = new IronSoftware.Drawing.Rectangle()
{ X = 215, Y = 1250, Height = 280, Width = 1335 }; //<-- the area you want in px
input.LoadPdf("example.pdf", ContentArea: contentArea);
var result = ocr.Read(input);
}
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
var contentArea = new IronSoftware.Drawing.Rectangle()
{ X = 215, Y = 1250, Height = 280, Width = 1335 }; //<-- the area you want in px
input.LoadPdf("example.pdf", ContentArea: contentArea);
var result = ocr.Read(input);
}
Imports IronOcr
Private ocr = New IronTesseract()
Using input = New OcrInput()
Dim contentArea = New IronSoftware.Drawing.Rectangle() With {
.X = 215,
.Y = 1250,
.Height = 280,
.Width = 1335
}
input.LoadPdf("example.pdf", ContentArea:= contentArea)
Dim result = ocr.Read(input)
End Using
API 參考: OcrInput OcrInput.Page