type TPdfStreamInspector = class ... end;
| Constructor | Description |
|---|---|
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 |
| Method | Description |
|---|---|
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 |
| Constant | Value | Purpose |
|---|---|---|
PdfStreamInspectDefaultSourceLimit | 512 MiB | Maximum retained source size |
PdfStreamInspectDefaultRawLimit | 256 MiB | Maximum raw payload copied by one operation |
PdfStreamInspectDefaultDecodedLimit | 256 MiB | Maximum decoded payload produced by one operation |
PdfStreamInspectDefaultExpansionRatio | 100 | Maximum decoded-to-encoded expansion ratio |
PdfStreamInspectDefaultMaxStreams | 1,000,000 | Maximum stream objects inventoried |
PdfStreamInspectDefaultDictionaryLimit | 1 MiB | Maximum dictionary bytes inspected for one stream |
| Type | Description |
|---|---|
TPdfStreamFilterKind | Classifies filters as psfkUnknown, psfkASCIIHex, psfkASCII85, psfkLZW, psfkFlate, psfkRunLength, psfkCCITTFax, psfkJBIG2, psfkDCT, psfkJPX, psfkCrypt or psfkBrotli |
TPdfStreamNativeAccess | Selects no native path, image-object access or embedded-file access |
TPdfStreamDecodeLevel | Selects raw, supported general-filter or required full-chain decoding |
TPdfStreamReadStatus | Reports psrsCompleted, psrsPartiallyDecoded, psrsInvalidIndex, psrsInvalidRange, psrsSourceLimitExceeded, psrsRawLimitExceeded, psrsDecodedLimitExceeded, psrsExpansionRatioExceeded, psrsUnsupportedFilter, psrsUnsupportedDecodeParameters, psrsEncrypted, psrsExternalData, psrsMalformed or psrsWriteError |
TPdfStreamFilterInfo | Filter name, Kind, HasDecodeParameters DecodeParms presence, Predictor, Colors, BitsPerComponent, Columns, and the LZW EarlyChange value |
TPdfStreamFilterInfos | Dynamic array of TPdfStreamFilterInfo records |
TPdfStreamInfo | Object 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 |
TPdfStreamInfos | Dynamic array of TPdfStreamInfo records |
TPdfStreamInspectOptions | Caller-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 |
TPdfStreamReadReport | Status, byte counts (InputByteCount, OutputByteCount), applied and remaining filter counts (AppliedFilterCount, RemainingFilterCount), failed filter index (FailedFilterIndex), and ErrorMessage text for one read |
| Member | Type | Description |
|---|---|---|
Count | Integer | Number of physical stream objects or revisions found in the source |
Infos[Index] | TPdfStreamInfo | Object number, generation, offsets, lengths, filters, DecodeParms, and native access classification |
Encrypted | Boolean | Whether the trailer declares document encryption |
Options | TPdfStreamInspectOptions | Normalised resource budgets used by the inspector |
SourceByteCount | Int64 | Number of input bytes retained for inspection |
psdlRaw copies the encoded stream bytes without applying filterspsdlGeneral applies ASCIIHex, ASCII85, LZW, Flate, RunLength, TIFF 8-bit and PNG predictors, then returns psrsPartiallyDecoded when an image or unknown codec remainspsdlFull requires the complete chain to use supported general filters and returns psrsUnsupportedFilter otherwisepsnaImageObject directs document-level callers to the native FPDFImageObj_GetImageDataRaw, FPDFImageObj_GetImageDataDecoded and image filter APIspsnaEmbeddedFile directs attachment callers to the native FPDFAttachment_GetFile pathpsrsEncrypted, because the public native ABI does not decrypt an arbitrary indirect stream by object numberTPdfStreamInspectOptions.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
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;