PDFium Delphi Component Docs

문서·주석·폼 시맨틱 비교

v3.265.0부터 Small Business와 Enterprise에서 Lib\SmallBusiness\FPdfSemanticDiff.pas, PDFiumPasSB / PDFiumLazSB, FPdfSmallBusiness로 사용할 수 있습니다. 공개 unit 이름과 네임스페이스는 변하지 않습니다. 수동 업그레이드 시 낡은 Enterprise 소스 사본은 직접 제거하세요. 에디션 매트릭스를 보세요

ComparePdfSemantics는 페이지 렌더링과 무관하게 annotation과 AcroForm widget 속성을 비교합니다. appearance 픽셀이 그대로여도 폼 값은 바뀔 수 있습니다

페이지 정렬이나 명시적 매핑에서 TPdfDiffPagePairs를 넘기세요. nil은 위치 기반 짝을 고르고, 명시적 매핑은 두 문서를 정확히 한 번씩 덮어야 하며 없는 쪽은 -1로 표시합니다

annotation 식별은 /NM 이름을, form-widget 식별은 완전히 한정된 필드 이름을 씁니다. 식별은 매핑된 페이지와 항목 종류 안에서 유효합니다

이름이 없거나 중복되면(같은 페이지에서 한 필드의 여러 widget 포함) 명시적인 사유와 함께 psckAmbiguous로 보고됩니다. annotation 배열 순서가 식별을 정하지 않습니다

지원 프로파일은 문자열, 플래그, 색, opacity, 테두리, markup, line·vertex·ink 기하, URI action, 필드 값, choice 라벨과 선택된 옵션, checkbox·radio 상태를 비교합니다

선택적 문서 메타데이터와 로컬 목적지

CompareDocumentMetadata의 기본값은 False이며 표준 Info 값 Title, Author, Subject, Keywords, Creator, Producer, CreationDate, ModDate를 비교합니다. 없거나 빈 값은 같은 것으로 치고 날짜 문자열은 문자 그대로 비교합니다

CompareXmpMetadata의 기본값은 False이며 파싱한 XMP 패킷의 네임스페이스 한정 속성을 양쪽마다 하나의 psikXmp 항목으로 비교합니다. bag, sequence, 언어 대체 컨테이너는 속성당 하나의 상한 있는 값으로 평탄화되고, 한쪽에만 있는 패킷은 모든 속성을 추가·제거로 보고하며 패딩, 패킷 래퍼 바이트, 공백은 무시합니다

CompareOutlines의 기본값은 False이며 문서 북마크 계층을 슬래시로 구분한 제목 경로가 키인 psikOutline 항목으로 비교합니다. 캡처 속성에는 Title, Depth, IsOpen, ChildCount, Style, Color, 매핑된 로컬 DirectDestination. / ActionDestination. 대상, ActionUri, ActionFilePath가 있습니다

CompareAttachments의 기본값은 False이며 문서 첨부 트리의 임베디드 파일을 파일 이름이 키인 psikAttachment 항목으로 비교합니다. 캡처 속성에는 Size, 소문자 16진 Sha256 페이로드 다이제스트, Subtype, Description, AFRelationship, 문자열 /Params 메타데이터가 있습니다

ComparePageAttributes의 기본값은 False이며 매핑된 페이지마다 페이지 수준 기하·회전·라벨을 하나의 psikPage 항목(식별자 Page)으로 비교합니다. 캡처 속성에는 MediaBox, CropBox, BleedBox, TrimBox, ArtBox(GeometryTolerance로 비교), Rotation(0, 90, 180, 270), PageLabel이 있습니다

CompareNamedDestinations의 기본값은 False이며 /Names /Dests와 구형 /Dests의 문서 수준 명명된 목적지를 목적지 이름이 키인 psikNamedDestination 항목으로 비교하고, 매핑된 Destination.TargetPair, Destination.View, GeometryTolerance 아래의 fit 파라미터를 캡처해 변경을 NamedDestinationChangeCount에 집계합니다

CompareStructureTree의 기본값은 False이며 논리 구조 트리(/StructTreeRoot)를 요소 ID가 있으면 ID:<ElementID>가, 없으면 트리 경로 Root[i]/Child[j]...가 키인 psikStructure 항목으로 비교합니다. 캡처 속성에는 RoleName, Depth, ChildCount, ContentItemCount, Title, AlternateText, ActualText, ExpansionText, Language, ElementID, ClassName, TableScope, TableHeaders, TableRowSpan, TableColSpan, ListNumbering, LayoutPlacement, LayoutBBox가 있고 변경은 StructureChangeCount에 집계됩니다

CompareOptionalContent의 기본값은 False이며 optional-content group(/OCProperties /OCGs)을 레이어 Name이 키인 psikOptionalContent 항목으로 비교합니다. 캡처 속성에는 Intents, ViewState, PrintState, ExportState, EffectiveVisible, Locked, RadioGroupIndex, PageElementSubtype, Language, LanguagePreferred, MinimumZoom, MaximumZoom가 있고 변경은 OptionalContentChangeCount에 집계됩니다

페이지 링크 주석은 LinkUri와 로컬 목적지에 더해 GoToR action의 ActionFilePath, RemoteDestination.PageNumber, RemoteDestination.Suffix, Launch action의 ActionFilePath, /S /Named action의 NamedAction(NextPage, PrevPage, FirstPage, LastPage)를 캡처합니다

CustomAnnotationKeys는 매칭된 annotation마다 최대 64개의 annotation 사전 키를 Custom:<key> 속성으로 비교합니다. 문자열 값은 문자 그대로, 숫자 값은 수로 비교하고 그 외 값 종류는 존재 여부만 보고합니다. 한쪽에 없는 키는 추가·제거로 보고됩니다

메타데이터 변경은 식별자 Document, 페이지/annotation 인덱스 -1, HasBounds False인 psikDocument를 씁니다. 오버레이 사각형을 만들지 않고 양쪽마다 항목 하나를 ComparedItemCount와 공유 MaxItems 예산에 더합니다

CompareLinkDestinations의 기본값은 False이며 링크 주석에 직접 /Dest와 로컬 GoTo 목적지를 더합니다. 명명된 목적지는 PDFium으로 풀어내고 원격 문서는 절대 열지 않습니다

DirectDestination.과 ActionDestination. 속성에는 TargetPair, View, ParameterCount, 인덱스 Parameter[n] 값, XYZ 뷰라면 HasX, HasY, HasZoom이 있습니다. TargetPair는 검증된 페이지 짝 배열의 인덱스이므로 이동한 페이지도 식별자를 유지합니다

뷰 파라미터는 GeometryTolerance를 씁니다. XYZ null 좌표는 명시적 0과 구별되고, XYZ가 아닌 뷰의 null-대-0 구별은 PDFium이 노출한 뷰 값을 따릅니다

풀 수 없는 로컬 대상과 일관성 없는 네이티브 읽기는 보고서 전체를 거부합니다. 새 값들은 기존 문자열·항목·변경·비교 예산을 사용합니다

CompareAppearanceStreams는 선택적으로 annotation appearance 스트림 내용을 비교합니다. 기본값은 꺼짐입니다

CompareAnnotations와 CompareForms는 해당 항목 종류를 고르고, GeometryTolerance의 기본값은 0.001 PDF 사용자 공간 포인트입니다

추가·제거·변경 항목에는 전·후 속성과 bounds가 따라옵니다. BuildSemanticDiffOverlays는 페이지·변경 인덱스와 함께 전·후 사각형을 나눠 돌려줍니다

모든 인덱스는 0 기반이고 bounds는 PDF 사용자 공간 포인트로 남습니다. 비트맵에 그리기 전에 해당 페이지의 회전·crop·뷰포트 변환을 적용하세요

페이지는 독립적인 네이티브 핸들로 로드되며 호출자의 현재 페이지와 폼 포커스를 유지하고 폼 action을 실행하지 않습니다

프로파일은 widget이 아닌 필드, 임의의 사용자 지정 사전, 임베디드 파일, 스크립트 action, 원격 목적지 내용, XMP 메타데이터, 사용자 지정 Info 키를 제외합니다. XFA 폼 비교는 명시적으로 거부됩니다

기본 한도는 페이지 짝 10,000개, 스캔 항목 4,096개, 변경 4,096개, 문자열당 1 MiB, 문자열 총합 16 MiB, 비교 16,777,216회입니다. 예산이 소진되면 불완전한 출력을 거부합니다

Complete는 성공한 완전 비교와 거부된 비교를 구별합니다. 결과에 명시적으로 모호한 식별자가 섞일 수 있으니 결과를 확정 매칭으로 치기 전에 AmbiguousCount를 확인하세요

TPdfSemanticDiffReport는 종류별 합계를 갖춘 Changes 배열과 양쪽 문서에서 읽은 항목 수(ComparedItemCount)를 반환하고, 비교가 거부되면 ErrorMessage에 사유를 담습니다

TPdfSemanticDiffOptions는 비교 스위치와 GeometryTolerance, 스캔 시작 전에 검증되는 예산 한도를 담습니다. Default 클래스 함수는 위에 문서화된 프리셋을 돌려줍니다

TPdfSemanticItemKind는 psikAnnotation 일반 주석과 psikFormWidget AcroForm widget을 나눕니다. psikDocument와 psikXmp는 선택적 문서 메타데이터 스냅샷을, psikOutline, psikAttachment, psikPage, psikNamedDestination, psikStructure, psikOptionalContent는 선택적 북마크·임베디드 파일·페이지 속성·이름 있는 destination·논리 구조·optional content 스냅샷을 담습니다. 식별 매칭이 항목 종류를 넘지 않습니다

TPdfSemanticItem은 비교 항목 하나를 Kind, Identity, 0 기반 PageIndex·AnnotationIndex, annotation 사각형의 HasBounds와 Bounds, 캡처된 Properties와 함께 스냅샷합니다

TPdfSemanticProperty는 캡처한 팩트 하나를 Name과 Value 짝으로 기록하고, TPdfSemanticProperties는 항목에 대해 캡처한 팩트의 동적 배열입니다

TPdfSemanticChangeKind는 각 결과를 psckAdded, psckRemoved, psckChanged, psckAmbiguous로 분류합니다. 살아남은 속성 차이가 없는 changed 항목은 버려집니다

TPdfSemanticPropertyChange는 Name으로 달라진 속성 하나를 식별하고 HasBefore·HasAfter 존재 플래그와 BeforeValue·AfterValue 값을 담습니다. TPdfSemanticPropertyChanges는 그 동적 배열입니다

TPdfSemanticChange는 Kind, 항목의 ItemKind와 Identity, 전·후 항목 스냅샷, Properties의 속성별 차이, 모호한 식별자가 실어 주는 AmbiguityReason 텍스트로 결과 하나를 기술합니다. TPdfSemanticChanges는 그 동적 배열입니다

TPdfSemanticSide는 오버레이 사각형의 문서로 pssBefore나 pssAfter를 고릅니다

TPdfSemanticOverlay은 하나의 사각형에 Side, 출처인 0 기반 PageIndex, Changes를 가리키는 ChangeIndex, 변경 Kind, PDF 사용자 공간의 Bounds를 표시합니다. TPdfSemanticOverlays는 그 동적 배열입니다

실제 Delphi/FPC Win32/Win64 인수 검증은 타깃마다 92개 assertion을 다루며, 저장/재열기 문서, 동일 픽셀 값 변경, Unicode 식별자, 페이지 이동, 모호성, 예산을 포함합니다

공개 선언

type
  TPdfSemanticItemKind = (psikAnnotation, psikFormWidget, psikDocument,
    psikXmp, psikOutline, psikAttachment, psikPage, psikNamedDestination,
    psikStructure, psikOptionalContent);
  TPdfSemanticChangeKind = (psckAdded, psckRemoved, psckChanged, psckAmbiguous);
  TPdfSemanticSide = (pssBefore, pssAfter);
  TPdfSemanticProperty = record
    Name: string;
    Value: WideString;
  end;
  TPdfSemanticProperties = array of TPdfSemanticProperty;
  TPdfSemanticCustomKeys = array of string;
  TPdfSemanticItem = record
    Kind: TPdfSemanticItemKind;
    Identity: WideString;
    PageIndex, AnnotationIndex: Integer;
    HasBounds: Boolean;
    Bounds: TPdfRectangle;
    Properties: TPdfSemanticProperties;
  end;
  TPdfSemanticPropertyChange = record
    Name: string;
    HasBefore, HasAfter: Boolean;
    BeforeValue, AfterValue: WideString;
  end;
  TPdfSemanticPropertyChanges = array of TPdfSemanticPropertyChange;
  TPdfSemanticChange = record
    Kind: TPdfSemanticChangeKind;
    ItemKind: TPdfSemanticItemKind;
    Identity: WideString;
    HasBefore, HasAfter: Boolean;
    BeforeItem, AfterItem: TPdfSemanticItem;
    Properties: TPdfSemanticPropertyChanges;
    AmbiguityReason: string;
  end;
  TPdfSemanticChanges = array of TPdfSemanticChange;
  TPdfSemanticOverlay = record
    Side: TPdfSemanticSide;
    PageIndex, ChangeIndex: Integer;
    Kind: TPdfSemanticChangeKind;
    Bounds: TPdfRectangle;
  end;
  TPdfSemanticOverlays = array of TPdfSemanticOverlay;
  TPdfSemanticDiffOptions = record
    CompareAnnotations, CompareForms, CompareAppearanceStreams: Boolean;
    CompareDocumentMetadata, CompareLinkDestinations: Boolean;
    CompareXmpMetadata: Boolean;
    CompareOutlines, CompareAttachments, ComparePageAttributes: Boolean;
    CompareNamedDestinations, CompareStructureTree, CompareOptionalContent: Boolean;
    CustomAnnotationKeys: TPdfSemanticCustomKeys;
    GeometryTolerance: Double;
    MaxPagePairs, MaxItems, MaxChanges, MaxStringBytes: Integer;
    MaxTotalStringBytes, MaxComparisons: Int64;
    class function Default: TPdfSemanticDiffOptions; static;
  end;
  TPdfSemanticDiffReport = record
    Complete: Boolean;
    Changes: TPdfSemanticChanges;
    AddedCount, RemovedCount, ChangedCount, AmbiguousCount: Integer;
    NamedDestinationChangeCount, StructureChangeCount, OptionalContentChangeCount: Integer;
    ComparedItemCount: Integer;
    ErrorMessage: string;
  end;

// Indices are zero based. Nil PagePairs selects positional pairing. Explicit
// pairs must cover both documents exactly once; -1 denotes an absent side
// Identity is scoped to a mapped page and item kind. Missing names and repeated
// names (including repeated widgets of one field) are reported as ambiguous
// No rendering, focus changes, form actions, or positional identity guessing
// are performed. Pages are opened independently of the caller's current page
// The supported profile covers strings, flags, colors, opacity, borders,
// markup/line/vertex/ink geometry, URI actions, field values/options/checks,
// and optionally appearance streams. Arbitrary dictionaries, embedded files,
// script actions and non-widget fields are not compared. Optional metadata
// covers standard Info tags and optional namespace-qualified XMP packet
// properties; optional local destinations use mapped page IDs
function ComparePdfSemantics(BeforePdf, AfterPdf: TPdf;
  const PagePairs: TPdfDiffPagePairs; const Options: TPdfSemanticDiffOptions;
  out Report: TPdfSemanticDiffReport): Boolean;

// Bounds remain in PDF user space, in points. Transform with the destination
// page's rotation/crop/viewport rather than treating them as bitmap pixels
function BuildSemanticDiffOverlays(const Report: TPdfSemanticDiffReport):
  TPdfSemanticOverlays;