IronOCR でトリミング領域と長方形を作成する
Curtis Chau
Updated: 2026年6月29日
IronOCR を使用して PDF のコンテンツ領域を設定するにはどうすればいいですか?
コンテンツエリアとPDF
OcrInput.LoadPdfとLoadPdfPageメソッドはすべてコンテンツエリアを追加するオプションがあります。
質問 - PDF のサイズはピクセル単位で決まるのではなく、コンテンツ領域は通常ピクセル単位で測定されるため、コンテンツ領域の大きさを知るにはどうすればよいでしょうか?
オプション1
OcrInput.TargetDPIのデフォルトは225で、これはPDF画像のサイズをピクセルで指示します。 IronOCR がこれを読み取ります。
オプション2(理想的な使用例)
OcrInput.LoadPdf()をPDFテンプレートで使用してください。- 入力の幅と高さを取得するには
OcrInput.GetPages()を使用してください。 - OCRエンジンが読み取る正確な画像を取得するには
OcrInput.GetPages().First().ToBitmap()を使用してください。 - エクスポートされた画像からピクセル単位でコンテンツ領域を測定できるようになりました。
- ターゲット座標は、特定の OCR 領域に使用できます (最終結果を参照)。
情報を取得するには:
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 Using最終結果:
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 リファレンス: OcrInput|OcrInput.ページ

テクニカルライター
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。
...
詳しく読む