PDFium Delphi Component Docs

TPdfStreamInspector class

Unit: FPdfStreamInspect
Read-only bounded inventory and extraction of arbitrary physical PDF stream objects

Syntax

type TPdfStreamInspector = class ... end;

Constructors

ConstructorDescription
Create(Source: TStream)Reads a seekable PDF source under default budgets and restores its original position
Create(Source: TStream; const Options: TPdfStreamInspectOptions)Reads a seekable PDF source under caller-selected budgets
Create(const Data: TBytes)Inspects an existing PDF byte array under default budgets
Create(const Data: TBytes; const Options: TPdfStreamInspectOptions)Inspects an existing PDF byte array under caller-selected budgets

Methods

MethodDescription
CopyRawData(Index, Destination, out Report)Copies the complete encoded payload of one stream object
CopyRawData(Index, Destination, Offset, Count, out Report)Copies a validated byte window without decoding the filter chain
DecodeData(Index, Destination, Level, out Report)Returns raw data or applies supported general filters in declaration order
PdfStreamFilterKindFromName(Name)Maps a full or abbreviated PDF filter name to TPdfStreamFilterKind

Default limits

ConstantValuePurpose
PdfStreamInspectDefaultSourceLimit512 MiBMaximum retained source size
PdfStreamInspectDefaultRawLimit256 MiBMaximum raw payload copied by one operation
PdfStreamInspectDefaultDecodedLimit256 MiBMaximum decoded payload produced by one operation
PdfStreamInspectDefaultExpansionRatio100Maximum decoded-to-encoded expansion ratio
PdfStreamInspectDefaultMaxStreams1,000,000Maximum stream objects inventoried
PdfStreamInspectDefaultDictionaryLimit1 MiBMaximum dictionary bytes inspected for one stream

Public types

TypeDescription
TPdfStreamFilterKindClassifies filters as psfkUnknown, psfkASCIIHex, psfkASCII85, psfkLZW, psfkFlate, psfkRunLength, psfkCCITTFax, psfkJBIG2, psfkDCT, psfkJPX, psfkCrypt or psfkBrotli
TPdfStreamNativeAccessSelects no native path, image-object access or embedded-file access
TPdfStreamDecodeLevelSelects raw, supported general-filter or required full-chain decoding
TPdfStreamReadStatusReports psrsCompleted, psrsPartiallyDecoded, psrsInvalidIndex, psrsInvalidRange, psrsSourceLimitExceeded, psrsRawLimitExceeded, psrsDecodedLimitExceeded, psrsExpansionRatioExceeded, psrsUnsupportedFilter, psrsUnsupportedDecodeParameters, psrsEncrypted, psrsExternalData, psrsMalformed or psrsWriteError
TPdfStreamFilterInfoFilter name, Kind, HasDecodeParameters DecodeParms presence, Predictor, Colors, BitsPerComponent, Columns, and the LZW EarlyChange value
TPdfStreamFilterInfosDynamic array of TPdfStreamFilterInfo records
TPdfStreamInfoObject identity (ObjectNumber, Generation, TypeName), offsets and lengths (ObjectOffset, DictionaryOffset, DictionaryLength, RawOffset, RawLength, DecodedLengthHint), layout flags (LengthIsIndirect, UsedEndStreamFallback), encryption and external-file flags (HasExternalFile, IsEncryptedDocument), type names (SubtypeName), native boundary (NativeAccess of psnaNone, psnaImageObject or psnaEmbeddedFile), and the declared Filters chain
TPdfStreamInfosDynamic array of TPdfStreamInfo records
TPdfStreamInspectOptionsCaller-selected source, payload (MaxRawBytes, MaxDecodedBytes), expansion (MaxExpansionRatio), object-count (MaxStreams), dictionary (MaxDictionaryBytes), token (MaxTokens), allocation (MaxAllocationBytes), and DeadlineMilliseconds deadline budgets with a static Default initialiser
TPdfStreamReadReportStatus, byte counts (InputByteCount, OutputByteCount), applied and remaining filter counts (AppliedFilterCount, RemainingFilterCount), failed filter index (FailedFilterIndex), and ErrorMessage text for one read

Properties

MemberTypeDescription
CountIntegerNumber of physical stream objects or revisions found in the source
Infos[Index]TPdfStreamInfoObject number, generation, offsets, lengths, filters, DecodeParms, and native access classification
EncryptedBooleanWhether the trailer declares document encryption
OptionsTPdfStreamInspectOptionsNormalised resource budgets used by the inspector
SourceByteCountInt64Number of input bytes retained for inspection

Decode levels and native boundaries

Budgets and reports

TPdfStreamInspectOptions.Default combines its source, payload, expansion, dictionary and stream ceilings with the current TPdfParserResourceBudget token, object, decoded-byte, expansion-ratio, allocation and deadline policy

TPdfStreamReadReport records status, input and output byte counts, applied and remaining filters, the failed filter index and destination write errors

The current implementation retains one bounded source copy to support reliable indirect-length resolution and repeatable random stream reads; use a lower MaxSourceBytes when processing untrusted uploads under a tighter memory budget

Example

var
  Inspector: TPdfStreamInspector;
  Output: TMemoryStream;
  Report: TPdfStreamReadReport;
begin
  Inspector := TPdfStreamInspector.Create(PdfBytes);
  Output := TMemoryStream.Create;
  try
    if Inspector.Count > 0 then
      Inspector.DecodeData(0, Output, psdlGeneral, Report);
  finally
    Output.Free;
    Inspector.Free;
  end;
end;