Content Stream Semantic Comparison
HPDFContentStream can normalize decoded PDF content into bounded canonical events and compare those events without treating harmless serialization choices as changes
Declarations
function HPDFNormalizeContentStreamGraphicsState(
const Bytes: TBytes; out Canonical: TBytes;
out Statistics: THPDFContentSemanticStatistics;
NumberTolerance: Double = 1E-9;
MaxOperations: Integer = 1000000;
MaxCanonicalBytes: Int64 = 67108864
): boolean;
function HPDFCompareContentStreamsSemantic(
const Left, Right: TBytes;
out Info: THPDFContentSemanticCompareInfo;
NumberTolerance: Double = 1E-9;
MaxOperations: Integer = 1000000;
MaxCanonicalBytes: Int64 = 67108864
): boolean;
Normalization
- Numbers are quantized by the caller tolerance and emitted with locale-independent spelling
- Literal and hexadecimal strings compare by decoded byte value, while arrays retain item type and order
- Graphics and text-state setters update an effective snapshot and redundant setters do not create events
qandQmaintain a full state stack but do not become events by themselves- Successive
cmoperators are multiplied in PDF order, so equivalent matrix factorizations compare equally - Each retained operator carries the effective matrix, line, color, external graphics, and text state that applies at that point
- Inline-image keys are normalized by the tokenizer and payloads use SHA-256 identities to avoid canonical-stream expansion
Diagnostics and bounds
THPDFContentSemanticStatistics reports token, operation, state-operation, redundant-state, normalized-event, maximum-stack-depth, canonical-byte, error-offset, validity, and limit information. Comparison also reports the first differing normalized event
Malformed nested dictionary operands, invalid state-operator arity, unmatched or unclosed graphics-state scopes, trailing operands, operation overflow, and canonical-byte overflow fail closed and never report equivalence
Pass decoded content bytes. Stream filter decoding and resource-name reconciliation across different resource dictionaries remain the caller's responsibility