기술 문서

PDFlibPas: Delphi에서 텍스트, 이미지, 글꼴 추출

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을 위한 글입니다. 텍스트, 이미지, 글꼴 추출을 단순한 컴포넌트 호출이 아니라 운영 환경의 문서 엔지니어링으로 다룹니다.

실제 위험은 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.

지원 패키지 설계

PDFlibPas가 배포된 후 가장 유용한 지원 패키지는 입력, 프로필, 출력, 그리고 실패한 정확한 단계를 설명하는 것입니다

  • 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

텍스트, 이미지, 글꼴 추출에 대한 엔지니어링 검토 노트

이 검토 노트를 사용해 기능이 데모 단계를 넘어섰고 출시, 지원, 고객 에스컬레이션 상황에서 설명할 수 있는지 확인합니다

  • 결정: whether output needs visual order, content-stream order, or search-oriented order. 구현상 핵심 지점: extract text runs with coordinates, font identity, Unicode mapping, and style signals. 승인 증거: font subset name, embedded state, encoding map, and ToUnicode status. 회귀 트리거: OCR layers can contain stale or misaligned text over scanned pages
  • 결정: image extraction format, color conversion, compression retention, and naming. 구현상 핵심 지점: extract images with page location, dimensions, color space, and original object data when needed. 승인 증거: warnings for hidden, clipped, rotated, or overlapping content. 회귀 트리거: PDF drawing order may not equal human reading order
  • 결정: font subset naming, encoding diagnostics, and missing ToUnicode handling. 구현상 핵심 지점: classify fonts by subset, embedded status, and encoding behavior. 승인 증거: page number, object reference, coordinates, decoded text, font, and confidence. 회귀 트리거: ligatures and custom encodings can make copied text differ from visible text
  • 결정: confidence flags for OCR layers, hidden text, clipped content, and rotated pages. 구현상 핵심 지점: produce an analysis report that distinguishes facts from inferred reading order. 승인 증거: image size, color space, compression, mask, and export filename. 회귀 트리거: images may be masks, soft masks, or repeated resources rather than standalone pictures
  • 결정: whether output needs visual order, content-stream order, or search-oriented order. 구현상 핵심 지점: scan page resources and content streams while preserving object references. 승인 증거: font subset name, embedded state, encoding map, and ToUnicode status. 회귀 트리거: OCR layers can contain stale or misaligned text over scanned pages
  • 결정: image extraction format, color conversion, compression retention, and naming. 구현상 핵심 지점: extract text runs with coordinates, font identity, Unicode mapping, and style signals. 승인 증거: warnings for hidden, clipped, rotated, or overlapping content. 회귀 트리거: PDF drawing order may not equal human reading order
  • 결정: font subset naming, encoding diagnostics, and missing ToUnicode handling. 구현상 핵심 지점: extract images with page location, dimensions, color space, and original object data when needed. 승인 증거: page number, object reference, coordinates, decoded text, font, and confidence. 회귀 트리거: 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 참고 사항

PDFlibPas should sit behind a small service boundary that receives files, streams, profiles, and credentials, then returns output paths, warnings, metrics, and validation status. 중요한 용어는 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;

운영 체크리스트

  • 워크플로는 빈 파일, 일반 고객 파일, 최악의 파일에서 실행합니다
  • 생성된 PDF는 대상 뷰어, 검증기, 프린터 또는 downstream 애플리케이션에서 엽니다
  • 제품 버전, 프로필 버전, 입력 해시, 출력 경로, 경과 시간, 경고 수를 기록합니다
  • 암호, 인증서, 임시 파일, 고객 데이터는 명확한 보존 규칙에 따라 관리합니다
  • 고객 파일이 새로운 경계 사례를 드러내면 회귀 문서를 추가합니다

제품 문서

PDFlibPas

추가 코드 예제

var
  ImgList, I: Integer;
begin
  Pdf.SelectPage(1);
  ImgList := Pdf.GetPageImageList(0);
  for I := 0 to Pdf.GetImageListCount(ImgList) - 1 do
  begin
    Writeln(Pdf.GetImageListItemFormatDesc(ImgList, I, 0));
    Pdf.SaveImageListItemDataToFile(ImgList, I, 0,
      Format('page1-img%.2d.bin', [I]));
  end;
  Pdf.ReleaseImageList(ImgList);
end;
var
  I: Integer;
begin
  Pdf.FindFonts;
  for I := 1 to Pdf.FontCount do        // font indexes start at 1, not 0
    if Pdf.SelectFont(Pdf.GetFontID(I)) = 1 then
      Writeln(Format('%s  type=%d  embedded=%d  subset=%d',
        [Pdf.FontName, Pdf.FontType,
         Pdf.GetFontIsEmbedded, Pdf.GetFontIsSubsetted]));
end;