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;