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 tokenizes the result as one logical page-content sequence
It preserves literal strings, hex strings, names, arrays, dictionaries, inline-image payloads, and unknown operators while canonicalizing 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 serialized 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. Each TPdfContentSemanticMark records FirstByte/AfterByte, ObjectIndex, MatchingMark, Opens, Name and Properties; each 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 behavior, 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 normalized 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 normalized 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 normalization |
TPdfContentNormalizeOptions | Normalization 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 | Serialized 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 initialized but normalization has not completed |
pcnsCompleted | Normalization completed successfully |
pcnsInputLimitExceeded | The logical input exceeded MaxInputBytesPerPage or a configured limit was not positive |
pcnsOutputLimitExceeded | The normalized 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 normalization encountered a content stream filter it cannot decode |
pcnsEncryptedDocument | Document-level normalization refused encrypted input |
pcnsSignedDocument | Document-level normalization refused signed input without authorization |
pcnsDocumentRewriteFailed | The enclosing PDF object-graph rewrite or verification failed |
pcnsResourceBudgetExceeded | The process-wide TPdfParserResourceBudget deadline was reached before normalization completed |
| Field | Description |
|---|---|
RemoveComments | Omits PDF comments while 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 normalized page stream when compression reduces its size |
SkipUnsafePages | Allows document-level normalization 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 normalized content sequence |
MaxTokensPerPage | Maximum number of tokens inspected for one page |
| Field | Description |
|---|---|
Status | Current TPdfContentNormalizeStatus |
SourceByteCount | Total source content bytes |
OutputByteCount | Total normalized or rewritten output bytes |
PageCount | Pages inspected by document-level normalization |
NormalizedPageCount | Pages successfully replaced with normalized content |
SkippedPageCount | Unsafe pages preserved unchanged under skip policy |
InputStreamCount | Source content streams joined into logical page sequences |
OutputStreamCount | Normalized content streams produced |
CoalescedArrayCount | Multi-stream /Contents arrays replaced by a single normalized stream |
TokenCount | Tokens processed |
CommentCount | Comments encountered, whether retained or removed |
InlineImageCount | Complete inline-image blocks preserved |
UnknownOperatorCount | Unrecognized 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