v3.265.0 から Small Business と Enterprise で利用可能です。Lib\SmallBusiness\FPdfSemanticDiff.pas、PDFiumPasSB / PDFiumLazSB、FPdfSmallBusiness で提供され、公開ユニット名と名前空間は変わりません。手動アップグレードでは古い Enterprise 側のソースコピーを削除してください。詳細はエディションマトリクスを参照してください
ComparePdfSemantics はページ描画とは独立して注釈と AcroForm ウィジェットの属性を比較します。外観のピクセルが同じでも、フォーム値は変わることがあります
ページ対応付けの TPdfDiffPagePairs または明示的な対応表を渡します。nil は位置順の組み合わせを選び、明示的な対応表は両文書をそれぞれ一度だけ網羅する必要があります。片側がない場合は -1 を使います
注釈の識別には /NM 名、フォームウィジェットには完全修飾フィールド名を使います。識別の範囲は対応ページと項目の種類です
名前の欠落や重複は、同じページにある同一フィールドの複数ウィジェットも含め、理由付きの psckAmbiguous として報告します。注釈配列の順序で識別することはありません
対応プロファイルは文字列、flags、色、不透明度、境界線、markup、line、vertex、ink の形状、URI アクション、フィールド値、選択肢ラベルと選択済み項目、checkbox/radio 状態を比較します
CompareDocumentMetadata は既定で false で、標準の Info 値 Title、Author、Subject、Keywords、Creator、Producer、CreationDate、ModDate を比較します。値の欠落と空は等価として扱い、日付文字列はリテラルに比較します
CompareXmpMetadata は既定で False であり、解析済み XMP パケットの名前空間修飾プロパティを側ごとに 1 つの psikXmp 項目として比較します。bag・sequence・言語代替コンテナはプロパティごとに 1 つの有界値へ平坦化され、片側にのみ存在するパケットは全プロパティを追加または削除として報告し、パディング、パケットラッパーのバイト、空白は無視されます
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 で、対応付けたページごとに 1 つの psikPage 項目(識別子 Page)として、ページレベルのジオメトリ、回転、ラベルを比較します。取得されるプロパティは MediaBox、CropBox、BleedBox、TrimBox、ArtBox(GeometryTolerance で比較)、Rotation(0、90、180、270)、PageLabel です
CompareNamedDestinations は既定で False で、/Names /Dests と旧形式 /Dests の文書レベル名前付き宛先を、宛先名をキーとする psikNamedDestination 項目として比較します。対応付けた Destination.TargetPair、Destination.View、fit パラメータを GeometryTolerance のもとで取得し、変更は NamedDestinationChangeCount に集計します
CompareStructureTree は既定で False で、論理構造ツリー(/StructTreeRoot)を psikStructure 項目として比較します。キーは、要素 ID があれば ID:<ElementID>、なければツリーパス Root[i]/Child[j]... です。取得されるプロパティは RoleName、Depth、ChildCount、ContentItemCount、Title、AlternateText、ActualText、ExpansionText、Language、ElementID、ClassName、TableScope、TableHeaders、TableRowSpan、TableColSpan、ListNumbering、LayoutPlacement、LayoutBBox で、変更は StructureChangeCount に集計します
CompareOptionalContent は既定で False で、オプショナルコンテンツグループ(/OCProperties /OCGs)を psikOptionalContent 項目として比較します。キーはレイヤーの Name です。取得されるプロパティは Intents、ViewState、PrintState、ExportState、EffectiveVisible、Locked、RadioGroupIndex、PageElementSubtype、Language、LanguagePreferred、MinimumZoom、MaximumZoom で、変更は OptionalContentChangeCount に集計します
ページのリンク注釈は、ActionFilePath・RemoteDestination.PageNumber・RemoteDestination.Suffix(GoToR アクション)、ActionFilePath(Launch アクション)、NamedAction とその値 NextPage・PrevPage・FirstPage・LastPage(/S /Named アクション)を、LinkUri とローカル宛先に加えて取得します
CustomAnnotationKeys はマッチした注釈ごとに比較対象の注釈辞書キーを最大 64 個指定し、Custom:<key> プロパティとして扱います。文字列値はそのまま、数値は数値として比較され、その他の値種別は存在のみを報告します。片側に存在しないキーは追加または削除として報告されます
メタデータの変更は psikDocument で、識別子は Document、ページ/注釈インデックスは -1、HasBounds は false になります。オーバーレイ矩形は生成せず、両側で 1 項目ずつ 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 で注釈の外観ストリーム内容も比較できます。既定では無効です
CompareAnnotations と CompareForms で各種類を選びます。GeometryTolerance の既定値は PDF ユーザー空間の 0.001 ポイントです
追加、削除、変更の項目には前後の属性と境界を含みます。BuildSemanticDiffOverlays はページ番号と変更番号を持つ、前後別々の矩形を返します
すべての番号は 0 始まりで、境界は PDF ユーザー空間のポイント単位です。ビットマップに描く前に、該当ページの回転、crop、viewport 変換を適用してください
ページは独立したネイティブハンドルで読み込み、呼び出し元の現在ページとフォームフォーカスを維持し、フォームアクションを避けます
ウィジェットでないフィールド、任意の独自辞書、埋め込みファイル、script アクション、リモート宛先の内容、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 ウィジェットを分けます。psikDocument と psikXmp はオプションの文書メタデータスナップショットを保持し、psikOutline、psikAttachment、psikPage、psikNamedDestination、psikStructure、psikOptionalContent は、ブックマーク・埋め込みファイル・ページ属性・名前付き destination・論理構造・オプショナルコンテンツの各オプションスナップショットを保持します。識別の対応付けが項目種別をまたぐことはありません
TPdfSemanticItem は比較対象の 1 項目をスナップショットとして保持します。Kind、Identity、0 始まりの PageIndex と AnnotationIndex、注釈矩形の HasBounds と Bounds、取得済みの Properties です
TPdfSemanticProperty は取得した 1 つの事実を Name と Value の対として記録し、TPdfSemanticProperties は項目に対して取得した事実の動的配列です
TPdfSemanticChangeKind は各結果を psckAdded、psckRemoved、psckChanged、psckAmbiguous に分類します。残ったプロパティ差分のない changed 項目は捨てられます
TPdfSemanticPropertyChange は Name で差分のある 1 つのプロパティを特定し、HasBefore と HasAfter の存在フラグ、BeforeValue と AfterValue の値を持ちます。TPdfSemanticPropertyChanges はその動的配列です
TPdfSemanticChange は 1 つの結果を、Kind、項目の ItemKind と Identity、before と after の項目スナップショット、Properties のプロパティごとの差分、曖昧な識別が運ぶ AmbiguityReason テキストとともに表します。TPdfSemanticChanges はその動的配列です
TPdfSemanticSide はオーバーレイ矩形のために pssBefore または pssAfter の文書を選びます
TPdfSemanticOverlay は 1 つの矩形を、Side、取得元の 0 始まり PageIndex、Changes への ChangeIndex、変更の Kind、PDF ユーザー空間の Bounds で示します。TPdfSemanticOverlays はその動的配列です
実際の Delphi/FPC Win32/Win64 受け入れ検証は対象ごとに 92 assertions を含み、保存/再読み込み、同一ピクセルでの値変更、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 unconfigured dictionaries,
// 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;