PDFium Delphi Component Docs

FPdfContentNormalize unit

Unit: FPdfContentNormalize
Syntax-preserving normalisation of one logical PDF page-content sequence and robust inline-image boundary detection

Syntax

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;

Description

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

Shared semantic-frame support

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

Constants

ConstantDescription
PdfContentNormalizeDefaultInputLimitDefault per-page logical input limit of 256 MiB
PdfContentNormalizeDefaultOutputLimitDefault per-page normalised output limit of 256 MiB
PdfContentNormalizeDefaultTokenLimitDefault per-page limit of 10000000 tokens

Functions

FunctionDescription
TPdfContentNormalizeOptions.DefaultEnables comment removal, balance validation, beneficial Flate compression and unsafe-page skipping; disallows signed rewrites and applies the three default limits
NormalizePdfContentSequenceReturns normalised bytes and a detailed report, or False with a failure status and diagnostic text
CollectPdfContentResourceUsesReturns the resource kind and decoded PDF name for every resource-consuming content operator within MaxTokens, or False for malformed or over-budget input
FindInlineImageBlockReturns offsets for the next complete inline-image block at or after StartPos
DecodePdfContentByteStringDecodes 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
PdfContentTextOperandHasBytesReports 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

Types

TypeDescription
TPdfContentNormalizeStatusOutcome or failure category for sequence and document normalisation
TPdfContentNormalizeOptionsNormalisation policy and per-page byte and token limits
TPdfContentNormalizeReportStatus, byte and page totals, stream and token metrics, syntax observations and diagnostic text
TPdfContentResourceKindResource values pcrkFont, pcrkXObject, pcrkExtGState, pcrkColorSpace, pcrkPattern, pcrkShading and pcrkProperties
TPdfContentResourceUseOne decoded resource Name together with its Kind
TPdfContentResourceUsesDynamic array of collected resource uses in content order
TPdfContentSemanticFrameSerialised declaration operations and native object boundaries shared with the reader and styled spacing workflows; see the dedicated TPdfContentSemanticFrame page

Status values

ValueMeaning
pcnsNotStartedThe report has been initialised but normalisation has not completed
pcnsCompletedNormalisation completed successfully
pcnsInputLimitExceededThe logical input exceeded MaxInputBytesPerPage or a configured limit was not positive
pcnsOutputLimitExceededThe normalised bytes would exceed MaxOutputBytesPerPage
pcnsTokenLimitExceededThe content sequence exceeded MaxTokensPerPage
pcnsMalformedTokenA PDF content token could not be read completely
pcnsUnresolvedInlineImageA complete inline-image payload boundary could not be found
pcnsUnbalancedStateRequired graphics, text, marked-content, compatibility, array or dictionary scope balance failed
pcnsUnsupportedFilterDocument-level normalisation encountered a content stream filter it cannot decode
pcnsEncryptedDocumentDocument-level normalisation refused encrypted input
pcnsSignedDocumentDocument-level normalisation refused signed input without authorisation
pcnsDocumentRewriteFailedThe enclosing PDF object-graph rewrite or verification failed
pcnsResourceBudgetExceededThe process-wide TPdfParserResourceBudget deadline was reached before normalisation completed

Options

FieldDescription
RemoveCommentsOmits PDF comments whilst retaining required token boundaries
RequireBalancedStateRequires balanced q/Q, BT/ET, marked-content, compatibility, array and dictionary scopes
CompressOutputAllows the document-level wrapper to Flate-compress a normalised page stream when compression reduces its size
SkipUnsafePagesAllows document-level normalisation to preserve a page unchanged after an unsafe or unsupported result instead of aborting the document rewrite
AllowSignedDocumentExplicitly permits a full rewrite of signed input, which invalidates existing signature byte ranges
MaxInputBytesPerPageMaximum total bytes across the supplied content streams for one page
MaxOutputBytesPerPageMaximum bytes permitted in the normalised content sequence
MaxTokensPerPageMaximum number of tokens inspected for one page

Report fields

FieldDescription
StatusCurrent TPdfContentNormalizeStatus
SourceByteCountTotal source content bytes
OutputByteCountTotal normalised or rewritten output bytes
PageCountPages inspected by document-level normalisation
NormalizedPageCountPages successfully replaced with normalised content
SkippedPageCountUnsafe pages preserved unchanged under skip policy
InputStreamCountSource content streams joined into logical page sequences
OutputStreamCountNormalised content streams produced
CoalescedArrayCountMulti-stream /Contents arrays replaced by a single normalised stream
TokenCountTokens processed
CommentCountComments encountered, whether retained or removed
InlineImageCountComplete inline-image blocks preserved
UnknownOperatorCountUnrecognised operators preserved verbatim
ErrorMessageDiagnostic text for the first failure

Inline-image offsets

See Also

FPdfCompress, TPdf.SaveAsNormalizedContent