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 起算。必須位於 [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;