PDFium Delphi Component Docs

SaveAsWithAssociateFilesToStream method

Component: TPdf  ·  Unit: PDFium
In-memory variant of SaveAsWithAssociateFiles — writes the PDF output with injected associated files into any seekable TStream without staging through disk

Syntax

function SaveAsWithAssociateFilesToStream(Stream: TStream; const Options: TAssocFilesOptions): Boolean;

StreamTStream. The target stream that receives the PDF data
OptionsTAssocFilesOptions. Injection options detailing files, metadata, and the target catalog or page attachment point

Return Value

Returns True if the PDF with injected associate files was successfully written to the stream, or False when the component is inactive or the saved document could not be prepared for injection; the stream is not written on failure

Description

SaveAsWithAssociateFilesToStream is the streaming counterpart to SaveAsWithAssociateFiles — it embeds associated files conforming to ISO 32000-2 ยง7.11.4 directly into the output stream instead of a file path

File names and descriptions are written exactly as in SaveAsWithAssociateFiles: Unicode-safe /UF and /Desc text strings plus a printable ASCII /F fallback name

Remarks

Example

var
  Stream: TMemoryStream;
  Opts: TAssocFilesOptions;
  F: TAssociateFile;
begin
  Stream := TMemoryStream.Create;
  try
    Opts := TAssocFilesOptions.Default;
    Opts.TargetPage := 0;

    F.FileName := 'data.xml';
    F.Content := GetXmlBytes;
    F.Relationship := afData;
    F.MIMEType := 'text/xml';

    SetLength(Opts.Files, 1);
    Opts.Files[0] := F;

    if Pdf1.SaveAsWithAssociateFilesToStream(Stream, Opts) then
    begin
      Stream.Position := 0;
      SendToNetwork(Stream);
    end;
  finally
    Stream.Free;
  end;
end;

See Also

SaveAsWithAssociateFiles, SaveAs