property AttachmentName[Index: Integer]: WString; // read only
每个 PDF 文件附件在其文件规范字典中都带有一个相关文件名,通常是作者磁盘上看到的原始文件名(例如 contract.docx 或 source-data.csv)。AttachmentName 会将该名称以 WString 形式暴露出来,以便在 UI 中显示、用作建议的另存为路径,或按扩展名匹配
返回的字符串会从 PDF 的 UTF-16BE 或 PDFDocEncoding 存储中解码,因此非 ASCII 名称(中文、西里尔文、带重音的拉丁文)能够正确往返。当原始作者只留下一个键值条目,而没有显式的 /F 或 /UF 文件名时,会返回空字符串
该属性为只读。这个 API 不提供重命名附件;如果你需要更改文件名,请用 DeleteAttachment 删除该槽位,再用 CreateAttachment 重新创建,然后通过 Attachment 重新写入字节
| Index | Integer。零基附件位置。必须位于 [0, AttachmentCount - 1]。传入越界索引会返回空字符串 |
\、/);某些创作工具会在名称中存储相对路径
var
I: Integer;
FileName: string;
begin
Pdf1.LoadFromFile('package.pdf');
ListBox1.Items.BeginUpdate;
try
ListBox1.Items.Clear;
for I := 0 to Pdf1.AttachmentCount - 1 do
begin
FileName := Pdf1.AttachmentName[I];
if FileName = '' then
FileName := Format('(unnamed #%d)', [I]);
ListBox1.Items.AddObject(FileName, TObject(I));
end;
finally
ListBox1.Items.EndUpdate;
end;
end;