IronOCR 사용한 작물 영역 및 사각형

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

IronOCR 사용하여 PDF에 콘텐츠 영역을 설정하는 방법은 무엇인가요?

콘텐츠 영역 및 PDF

OcrInput.LoadPdfLoadPdfPage 메서드는 모두 ContentArea를 추가할 수 있는 옵션이 있습니다.

질문은 다음과 같습니다. PDF 파일의 크기는 픽셀 단위로 표시되지 않지만, 콘텐츠 영역은 일반적으로 픽셀 단위로 측정되는데, 콘텐츠 영역의 크기를 어떻게 알 수 있을까요?

옵션 1

OcrInput.TargetDPI의 기본값은 225이며, 이는 PDF 이미지의 크기를 픽셀로 지정합니다. IronOCR 이를 읽을 것입니다.

옵션 2 (이상적인 사용 사례)

  1. PDF 템플릿에 OcrInput.LoadPdf()을 사용합니다.
  2. 입력의 너비와 높이를 얻기 위해 OcrInput.GetPages()을 사용합니다.
  3. OCR 엔진이 읽을 정확한 이미지를 얻기 위해 OcrInput.GetPages().First().ToBitmap()을 사용합니다.
  4. 이제 내보낸 이미지에서 ContentAreas를 픽셀 단위로 측정할 수 있습니다.
  5. 목표 좌표는 특정 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");
}
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");
}
$vbLabelText   $csharpLabel

최종 결과:

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);
}
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);
}
$vbLabelText   $csharpLabel

API 참조: OcrInput | OcrInput.페이지

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

시작할 준비 되셨나요?
Nuget 다운로드 5,525,971 | 버전: 2026.3 방금 출시되었습니다
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronOcr
샘플을 실행하세요 이미지가 검색 가능한 텍스트로 바뀌는 것을 확인해 보세요.