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; overload;
function DecodeLoadedStreamToStream(AStream: THPDFStreamObject;
  Output: TStream; CancellationToken: THPDFCancellationToken;
  out Info: THPDFDecodePipelineInfo): Boolean; overload;

Unit

HPDFDoc

Parameters

NamePurpose
AStreamLoaded THPDFStreamObject whose /Filter entry is decoded
OutputCaller-owned destination that receives decoded bytes at its current position
CancellationTokenOptional cooperative cancellation shared with custom filter stages
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;
  CustomFilterCount: Integer;
  CustomFilterFailureCount: 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, decoder failures, custom failures, cancellation, and seek-contract violations

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