기술 문서

PDFlibPas: Delphi에서 text, image, and font extraction

losLab PDF Library는 Delphi 및 C++Builder 팀에 소스 제공 PDF 엔진을 제공합니다. 데스크톱, 서버, DLL, ActiveX, Dylib 워크플로에서 PDF/A 및 PDF/UA 검사, PAdES 서명 지원, 렌더러 선택을 외부 PDF 서비스 없이 사용할 수 있습니다.

이 글은 teams building PDF analysis, migration, search, evidence capture, or support-inspection tools을 위한 글입니다. text, image, and font extraction을 단순한 컴포넌트 호출이 아니라 운영 환경의 문서 엔지니어링으로 다룹니다.

실제 위험은 extraction output is easy to over-trust even though PDF content order, font encoding, image color spaces, and page resources rarely match user-visible reading order exactly입니다. 따라서 명확한 계약, 관찰 가능한 진단, 실제 고객 파일을 반영한 회귀 샘플이 필요합니다.

아키텍처 결정

Separate extraction facts from interpretation. whether output needs visual order, content-stream order, or search-oriented order / image extraction format, color conversion, compression retention, and naming

  • whether output needs visual order, content-stream order, or search-oriented order
  • image extraction format, color conversion, compression retention, and naming
  • font subset naming, encoding diagnostics, and missing ToUnicode handling
  • confidence flags for OCR layers, hidden text, clipped content, and rotated pages

구현 흐름

Preserve page and resource context. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. scan page resources and content streams while preserving object references
  2. extract text runs with coordinates, font identity, Unicode mapping, and style signals
  3. extract images with page location, dimensions, color space, and original object data when needed
  4. classify fonts by subset, embedded status, and encoding behavior
  5. produce an analysis report that distinguishes facts from inferred reading order

검증 증거

Extraction evidence that remains explainable. Keep these fields with the output or support record.

  • page number, object reference, coordinates, decoded text, font, and confidence
  • image size, color space, compression, mask, and export filename
  • font subset name, embedded state, encoding map, and ToUnicode status
  • warnings for hidden, clipped, rotated, or overlapping content

Extracted text is not always authored text

A professional extraction workflow should record where each text run, image, and font resource came from, how it was decoded, and which assumptions were used to group it into searchable or reviewable content.

Support package design

Once PDFlibPas is deployed, the most valuable support package is the one that explains the input, profile, output, and exact stage that failed.

  • page number, object reference, coordinates, decoded text, font, and confidence
  • image size, color space, compression, mask, and export filename
  • font subset name, embedded state, encoding map, and ToUnicode status
  • warnings for hidden, clipped, rotated, or overlapping content
  • terminology snapshot: text extraction, image extraction, font resource, ToUnicode

Engineering review notes for text, image, and font extraction

Use these review notes to make sure the feature has moved beyond a demo and can be defended during release, support, and customer escalation.

  • Decision: whether output needs visual order, content-stream order, or search-oriented order. Implementation pressure point: extract text runs with coordinates, font identity, Unicode mapping, and style signals. Acceptance evidence: font subset name, embedded state, encoding map, and ToUnicode status. Regression trigger: OCR layers can contain stale or misaligned text over scanned pages
  • Decision: image extraction format, color conversion, compression retention, and naming. Implementation pressure point: extract images with page location, dimensions, color space, and original object data when needed. Acceptance evidence: warnings for hidden, clipped, rotated, or overlapping content. Regression trigger: PDF drawing order may not equal human reading order
  • Decision: font subset naming, encoding diagnostics, and missing ToUnicode handling. Implementation pressure point: classify fonts by subset, embedded status, and encoding behavior. Acceptance evidence: page number, object reference, coordinates, decoded text, font, and confidence. Regression trigger: ligatures and custom encodings can make copied text differ from visible text
  • Decision: confidence flags for OCR layers, hidden text, clipped content, and rotated pages. Implementation pressure point: produce an analysis report that distinguishes facts from inferred reading order. Acceptance evidence: image size, color space, compression, mask, and export filename. Regression trigger: images may be masks, soft masks, or repeated resources rather than standalone pictures
  • Decision: whether output needs visual order, content-stream order, or search-oriented order. Implementation pressure point: scan page resources and content streams while preserving object references. Acceptance evidence: font subset name, embedded state, encoding map, and ToUnicode status. Regression trigger: OCR layers can contain stale or misaligned text over scanned pages
  • Decision: image extraction format, color conversion, compression retention, and naming. Implementation pressure point: extract text runs with coordinates, font identity, Unicode mapping, and style signals. Acceptance evidence: warnings for hidden, clipped, rotated, or overlapping content. Regression trigger: PDF drawing order may not equal human reading order
  • Decision: font subset naming, encoding diagnostics, and missing ToUnicode handling. Implementation pressure point: extract images with page location, dimensions, color space, and original object data when needed. Acceptance evidence: page number, object reference, coordinates, decoded text, font, and confidence. Regression trigger: ligatures and custom encodings can make copied text differ from visible text

경계 사례

  • PDF drawing order may not equal human reading order
  • ligatures and custom encodings can make copied text differ from visible text
  • images may be masks, soft masks, or repeated resources rather than standalone pictures
  • OCR layers can contain stale or misaligned text over scanned pages

Delphi / C++Builder notes

PDFlibPas should sit behind a small service boundary that receives files, streams, profiles, and credentials, then returns output paths, warnings, metrics, and validation status. Important terms include text extraction, image extraction, font resource, ToUnicode, content stream, coordinates.

Delphi 코드 예제

다음 Delphi 스케치는 이 주제에 맞는 실무형 서비스 경계를 보여 줍니다. 정책 검사, 로깅, 검증을 좁은 제품 호출 구간 밖에 두면 워크플로를 테스트하기 쉽습니다.

procedure ExtractForIndexing(const FileName, OutputDir: string);
var
  Pdf: TPDFlib;
begin
  Pdf := TPDFlib.Create;
  try
    Pdf.LoadFromFile(FileName, '');
    SaveExtractedText(OutputDir, ExtractDocumentText(Pdf));
    SaveEmbeddedImages(OutputDir, ExtractDocumentImages(Pdf));
    SaveFontInventory(OutputDir, BuildFontInventory(Pdf));
  finally
    Pdf.Free;
  end;
end;

운영 체크리스트

  • Run the workflow on an empty file, a normal customer file, and a worst-case file
  • Open the generated PDF with the target viewer, validator, printer, or downstream application
  • Log product version, profile version, input hash, output path, elapsed time, and warning count
  • Keep passwords, certificates, temporary files, and customer data under explicit retention rules
  • Add regression documents when a customer file exposes a new edge case

Product documentation

PDFlibPas