function SaveAsWithAssociateFiles(const FileName: string; const Options: TAssocFilesOptions): Boolean;
| FileName | string. The target output file path |
| Options | TAssocFilesOptions. Injection options detailing files, metadata, and the target catalog or page attachment point |
True if the PDF with injected associate files was successfully saved, or False when the component is inactive or the saved document could not be prepared for injection; the target file is created or replaced only on success, so a failed call leaves an existing file untouchedSaveAsWithAssociateFiles 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
TAssociateFile.MIMEType takes the ordinary MIME value, such as text/plain; PDF name delimiters and special bytes are escaped during serialisation, so callers must not pre-escape the slash
TAssocFilesOptions.TargetPage is 0 for the catalog or the 1-based page position in document page order, the order in which viewers display the pages, regardless of where the page objects are stored in the file; any other value raises EPdfError rather than falling back to the catalog
TAssociateFile.FileName and TAssociateFile.Description accept any Unicode text: /UF and /Desc are written as PDF text strings (UTF-16BE with a byte order mark whenever the value is not plain printable ASCII), whilst /F keeps a portable ASCII copy of the name in which every other character becomes _
saRemoveSecurity)TAssocFilesOptions structure, specifying filenames, content arrays, MIME types, and relationships/AF only and are not added to the /EmbeddedFiles name tree, so after reopening the output they are not listed by AttachmentCount or the other indexed attachment properties
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;