function SaveAsWithAssociateFiles(const FileName: string; const Options: TAssocFilesOptions): Boolean;
| FileName | string。目標輸出檔案路徑 |
| Options | TAssocFilesOptions。注入選項,詳細指定檔案、中繼資料以及目標目錄或頁面附加點 |
True;當元件非作用中,或儲存後的文件無法準備供注入時,傳回 False。目標檔案只在成功時才建立或取代,因此失敗的呼叫不會動到既有的檔案SaveAsWithAssociateFiles 實作 PDF 2.0 Associate Files 插入(ISO 32000-2 §7.11.4)
此方法可將 XML 資料、來源結構描述或範本等檔案附加到目錄或個別頁面,並帶有明確的 /AFRelationship 中繼資料
TAssociateFile.Description 會寫入人類可讀的檔案規格 /Desc 值,供無障礙與探索工作流程使用
TAssociateFile.MIMEType 接受一般的 MIME 值,例如 text/plain;序列化時會跳脫 PDF 名稱分隔字元與特定位元組,因此呼叫端不可預先跳脫斜線
TAssocFilesOptions.TargetPage 為 0 時附加到 catalog,否則是文件頁面順序中從 1 起算的頁面位置,也就是檢視器顯示頁面的順序,與頁面物件儲存在檔案中的位置無關;其他值會引發 EPdfError,而不是退回 catalog
TAssociateFile.FileName 與 TAssociateFile.Description 接受任何 Unicode 文字:/UF 與 /Desc 以 PDF 文字字串寫入(只要值不是純可列印 ASCII,就採用帶位元組順序標記的 UTF-16BE),而 /F 保留一份可攜的 ASCII 檔名副本,其中其餘字元一律換成 _
saRemoveSecurity)TAssocFilesOptions 結構提供,指定檔名、內容陣列、MIME 類型與關聯性/AF 引用,不會加入 /EmbeddedFiles 名稱樹,因此重新開啟輸出後,AttachmentCount 與其他索引式附件屬性都不會列出它們
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;