Content Stream Semantic Comparison
HPDFContentStream can normalise decoded PDF content into bounded canonical events and compare those events without treating harmless serialisation 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;
Normalisation
- Numbers are quantised by the caller tolerance and emitted with locale-independent spelling
- Literal and hexadecimal strings compare by decoded byte value, whilst 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 factorisations compare equally - Each retained operator carries the effective matrix, line, colour, external graphics and text state that applies at that point
- Inline-image keys are normalised 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, normalised-event, maximum-stack-depth, canonical-byte, error-offset, validity and limit information. Comparison also reports the first differing normalised 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