const
PdfContentNormalizeDefaultInputLimit = Int64(256) * 1024 * 1024;
PdfContentNormalizeDefaultOutputLimit = Int64(256) * 1024 * 1024;
PdfContentNormalizeDefaultTokenLimit = 10000000;
function NormalizePdfContentSequence(const Streams: array of TBytes;
const Options: TPdfContentNormalizeOptions; out Output: TBytes;
out Report: TPdfContentNormalizeReport): Boolean;
function CollectPdfContentResourceUses(const Data: TBytes;
MaxTokens: Integer;
out ResourceUses: TPdfContentResourceUses): Boolean;
function FindInlineImageBlock(const Data: TBytes; StartPos: Integer;
out BiPos, IdPos, DataStart, EndImageStart: Integer): Boolean;
NormalizePdfContentSequence joins the supplied content streams in array order and tokenises the result as one logical page-content sequence
It preserves literal strings, hex strings, names, arrays, dictionaries, inline-image payloads and unknown operators whilst canonicalising token separation; comments can be removed and structural balance can be required
CollectPdfContentResourceUses records resource names consumed by text, XObject, graphics-state, colour-space, pattern, shading, marked-content property and inline-image operators under the central token budget
FindInlineImageBlock locates a complete BI, ID and EI block without treating an EI byte sequence inside image payload data as the terminator
Since v3.289.0, TPdfContentSemanticFrame describes serialised declaration operations and native object boundaries through its Data bytes, an Objects: TPdfContentObjectBoundaries array of TPdfContentObjectBoundary records and a Marks: TPdfContentSemanticMarks array of TPdfContentSemanticMark records whose Opens/MatchingMark pairing sequences begin and end marks. Every TPdfContentSemanticMark records FirstByte/AfterByte, ObjectIndex, MatchingMark, Opens, Name and Properties, while every TPdfContentObjectBoundary records FirstByte, AfterByte and Kind. DecodePdfContentByteString decodes raw literal/hexadecimal font bytes without imposing Unicode semantics; PdfContentTextOperandHasBytes validates Tj/TJ-style string operands and identifies whether a native text slot is required
The reader and styled spacing workflows share this byte-level behaviour, including escaped continuation-only strings, empty arrays and numeric-only TJ positioning. Semantic-property Unicode decoding remains a separate step
| Constant | Description |
|---|---|
PdfContentNormalizeDefaultInputLimit | Default per-page logical input limit of 256 MiB |
PdfContentNormalizeDefaultOutputLimit | Default per-page normalised output limit of 256 MiB |
PdfContentNormalizeDefaultTokenLimit | Default per-page limit of 10000000 tokens |
| Function | Description |
|---|---|
TPdfContentNormalizeOptions.Default | Enables comment removal, balance validation, beneficial Flate compression and unsafe-page skipping; disallows signed rewrites and applies the three default limits |
NormalizePdfContentSequence | Returns normalised bytes and a detailed report, or False with a failure status and diagnostic text |
CollectPdfContentResourceUses | Returns the resource kind and decoded PDF name for every resource-consuming content operator within MaxTokens, or False for malformed or over-budget input |
FindInlineImageBlock | Returns offsets for the next complete inline-image block at or after StartPos |
DecodePdfContentByteString | Decodes one literal or hexadecimal PDF string operand to raw bytes without imposing Unicode semantics, raising EConvertError for other object shapes, trailing tokens or malformed escapes |
PdfContentTextOperandHasBytes | Reports whether a Tj string or TJ array operand carries at least one decoded byte, raising EConvertError for non-string or non-numeric TJ entries and malformed arrays |
| Type | Description |
|---|---|
TPdfContentNormalizeStatus | Outcome or failure category for sequence and document normalisation |
TPdfContentNormalizeOptions | Normalisation policy and per-page byte and token limits |
TPdfContentNormalizeReport | Status, byte and page totals, stream and token metrics, syntax observations and diagnostic text |
TPdfContentResourceKind | Resource values pcrkFont, pcrkXObject, pcrkExtGState, pcrkColorSpace, pcrkPattern, pcrkShading and pcrkProperties |
TPdfContentResourceUse | One decoded resource Name together with its Kind |
TPdfContentResourceUses | Dynamic array of collected resource uses in content order |
TPdfContentSemanticFrame | Serialised declaration operations and native object boundaries shared with the reader and styled spacing workflows; see the dedicated TPdfContentSemanticFrame page |
| Value | Meaning |
|---|---|
pcnsNotStarted | The report has been initialised but normalisation has not completed |
pcnsCompleted | Normalisation completed successfully |
pcnsInputLimitExceeded | The logical input exceeded MaxInputBytesPerPage or a configured limit was not positive |
pcnsOutputLimitExceeded | The normalised bytes would exceed MaxOutputBytesPerPage |
pcnsTokenLimitExceeded | The content sequence exceeded MaxTokensPerPage |
pcnsMalformedToken | A PDF content token could not be read completely |
pcnsUnresolvedInlineImage | A complete inline-image payload boundary could not be found |
pcnsUnbalancedState | Required graphics, text, marked-content, compatibility, array or dictionary scope balance failed |
pcnsUnsupportedFilter | Document-level normalisation encountered a content stream filter it cannot decode |
pcnsEncryptedDocument | Document-level normalisation refused encrypted input |
pcnsSignedDocument | Document-level normalisation refused signed input without authorisation |
pcnsDocumentRewriteFailed | The enclosing PDF object-graph rewrite or verification failed |
pcnsResourceBudgetExceeded | The process-wide TPdfParserResourceBudget deadline was reached before normalisation completed |
| Field | Description |
|---|---|
RemoveComments | Omits PDF comments whilst retaining required token boundaries |
RequireBalancedState | Requires balanced q/Q, BT/ET, marked-content, compatibility, array and dictionary scopes |
CompressOutput | Allows the document-level wrapper to Flate-compress a normalised page stream when compression reduces its size |
SkipUnsafePages | Allows document-level normalisation to preserve a page unchanged after an unsafe or unsupported result instead of aborting the document rewrite |
AllowSignedDocument | Explicitly permits a full rewrite of signed input, which invalidates existing signature byte ranges |
MaxInputBytesPerPage | Maximum total bytes across the supplied content streams for one page |
MaxOutputBytesPerPage | Maximum bytes permitted in the normalised content sequence |
MaxTokensPerPage | Maximum number of tokens inspected for one page |
| Field | Description |
|---|---|
Status | Current TPdfContentNormalizeStatus |
SourceByteCount | Total source content bytes |
OutputByteCount | Total normalised or rewritten output bytes |
PageCount | Pages inspected by document-level normalisation |
NormalizedPageCount | Pages successfully replaced with normalised content |
SkippedPageCount | Unsafe pages preserved unchanged under skip policy |
InputStreamCount | Source content streams joined into logical page sequences |
OutputStreamCount | Normalised content streams produced |
CoalescedArrayCount | Multi-stream /Contents arrays replaced by a single normalised stream |
TokenCount | Tokens processed |
CommentCount | Comments encountered, whether retained or removed |
InlineImageCount | Complete inline-image blocks preserved |
UnknownOperatorCount | Unrecognised operators preserved verbatim |
ErrorMessage | Diagnostic text for the first failure |
BiPos is the byte offset of the BI keywordIdPos is the byte offset of the ID keywordDataStart is the first payload byte after the single required whitespace following IDEndImageStart is the byte offset of the terminating EI keyword and therefore one byte past the payloadFalse when no complete block is found at or after StartPos