THotPDF.DecodeLoadedStreamToStream Method
Decodes a loaded PDF stream through its complete filter chain and writes the final stage directly to a caller-owned stream
Declaration
function DecodeLoadedStreamToStream(AStream: THPDFStreamObject; Output: TStream; out Info: THPDFDecodePipelineInfo): boolean;
Unit
HPDFDoc
Parameters
| Name | Purpose |
|---|---|
AStream | Loaded THPDFStreamObject whose /Filter entry is decoded |
Output | Caller-owned destination that receives decoded bytes at its current position |
Info | Receives input and output byte counts, filter counts, depth, status, failing filter, and diagnostics |
Return value
Returns True only when every requested stage succeeds
Usage notes
- The final filter writes to
Outputwithout creating a second full-size final memory stream - Intermediate stages use
THPDFAdaptiveTempStreamand spill to owned temporary files afterLoadedStreamMemoryThreshold - Every stage remains bounded by
DecodeBudgetBytesand every decoded byte also consumesDocumentDecodeBudgetBytes - ASCII85 requires an exact
~>end marker and ASCIIHex requires>; malformed loaded pipelines fail instead of accepting truncated data DecodeFilterLimitrejects oversized arrays before stage allocationDecodePipelineDepthLimit, cyclic indirect-reference detection, and same-stream recursion detection bound hostile object graphs- The source stream position is restored after success or failure
- A failed streaming destination can contain bytes already accepted before the failure; use a temporary destination when atomic output is required
Diagnostics
THPDFDecodePipelineInfo = record
Status: THPDFDecodePipelineStatus;
InputBytes: Int64;
OutputBytes: Int64;
FilterCount: Integer;
AppliedFilterCount: Integer;
PipelineDepth: Integer;
StopBeforeLast: Boolean;
FailedFilter: AnsiString;
Diagnostic: AnsiString;
end;
Status distinguishes invalid streams and filters, filter-count and depth limits, cyclic references, recursive streams, unsupported filters, budget failures, and decoder failures
Example
Output := TFileStream.Create('payload.bin', fmCreate);
try
if not PDF.DecodeLoadedStreamToStream(StreamObject, Output, Info) then
raise Exception.Create(String(Info.Diagnostic));
finally
Output.Free;
end;