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

NamePurpose
AStreamLoaded THPDFStreamObject whose /Filter entry is decoded
OutputCaller-owned destination that receives decoded bytes at its current position
InfoReceives 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

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;

Related APIs