PDFium Delphi Component Docs

SaveAsWithAssociateFiles method

Component: TPdf  ·  Unit: PDFium
Saves the active PDF to a file path while injecting associated files into the catalog or pages conforming to ISO 32000-2 §7.11.4

Syntax

function SaveAsWithAssociateFiles(const FileName: string; const Options: TAssocFilesOptions): Boolean;

FileNamestring. The target output file path
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 saved, or False on failure

Description

SaveAsWithAssociateFiles implements PDF 2.0 Associate Files injection (ISO 32000-2 §7.11.4)

The method attaches files such as XML data, source schemas, or templates to the catalog or individual pages with explicit /AFRelationship metadata

TAssociateFile.Description writes the human-readable file-specification /Desc value used by accessibility and discovery workflows

Remarks

Example

var
  Opts: TAssocFilesOptions;
  F: TAssociateFile;
begin
  Opts := TAssocFilesOptions.Default;
  Opts.TargetPage := 0; // catalog-level attachment

  F.FileName := 'data.xml';
  F.Description := 'Source data for this document';
  F.Content := GetXmlBytes;
  F.Relationship := afData;
  F.MIMEType := 'text/xml';

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

  if Pdf1.SaveAsWithAssociateFiles('output.pdf', Opts) then
    ShowMessage('PDF with associate files saved successfully');
end;

See Also

SaveAsWithAssociateFilesToStream, SaveAs