property AttachmentRelationship[Index: Integer]: WString; // read only
PDF 2.0 的關聯檔案機制(ISO 32000-2 §7.11.4)會在每個檔案規格上標記一個 /AFRelationship 名稱,用來說明內嵌檔案與其所附內容之間的關係:Source、Data、Alternative、Supplement、EncryptedPayload、FormData、Schema 或 Unspecified(Table 43)。PDF/A-3 以及 ZUGFeRD / Factur-X 電子發票就是靠這個項目標記可供機器讀取的 XML 承載
此屬性透過原生 FPDFAttachment_GetAFRelationship 匯出讀取該項目,並以 Unicode 字串傳回原始名稱代碼。當檔案規格沒有 /AFRelationship 項目、該項目不是名稱,或已載入的 pdfium.dll 早於此匯出時(請參閱 AttachmentRelationshipFeaturesAvailable),則傳回空字串
此屬性為唯讀。若要以關聯關係附加檔案,請使用 FPdfAssocFiles 的 Pascal 端寫入器,它會發出相同的名稱代碼
| Index | Integer。以 0 起算的附件槽位。必須滿足 0 <= Index < AttachmentCount;其他值會引發 EPdfError(Incorrect attachment index) |
/EmbeddedFiles 名稱樹中的附件才有索引;僅由 /AF 陣列引用的關聯檔案無法透過此屬性存取(見 AttachmentCount)TPdfAttachmentMetadata 的 Relationship 欄位;TryGetAnnotationFileAttachment 則會為檔案附件註解填入對應欄位
var
I: Integer;
begin
Pdf1.LoadFromFile('invoice-facturx.pdf');
for I := 0 to Pdf1.AttachmentCount - 1 do
if Pdf1.AttachmentRelationship[I] = 'Alternative' then
SaveInvoiceXml(Pdf1.AttachmentName[I], Pdf1.Attachment[I]);
end;