function SaveAsWithAssociateFilesToStream(Stream: TStream; const Options: TAssocFilesOptions): Boolean;
| Stream | TStream. The target stream that receives the PDF data |
| Options | TAssocFilesOptions. Injection options detailing files, metadata, and the target catalogue or page attachment point |
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 failureSaveAsWithAssociateFilesToStream 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
Write and Seek operationsOptions.TargetPage must be 0 (catalogue) or a page number from 1 to PageCount in document page order; any other value raises EPdfErrorInjectAssociateFiles procedure raises EPdfAssocFilesError when the source has no readable trailer or catalogue, or when TargetPage does not name an existing page, and leaves the destination stream unmodified
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;