property AttachmentName[Index: Integer]: WString; // read only
Every PDF file attachment carries an associated file name in its file specification dictionary — typically the original file name as it appeared on the author's disk (for example contract.docx or source-data.csv). AttachmentName exposes that name as a WString そのため、UI に表示したり、保存先候補の path として使ったり、拡張子で照合したりできます
返される string は PDF の UTF-16BE または PDFDocEncoding の格納形式からデコードされるため、非 ASCII 名 (Chinese、Cyrillic、accented Latin) も正しく round-trip します。元の作成者が明示的な /F または /UF filename を付けずに key entry だけを残している場合は、空文字列が返ります
この property は読み取り専用です。添付ファイルの名前変更はこの API では公開されていません。filename を変更したい場合は、次を使って slot を削除してください DeleteAttachment and recreate it with CreateAttachment, then re-assign the bytes through Attachment.
| Index | Integer. Zero-based attachment position. Must be in [0, AttachmentCount - 1]。範囲外の index を渡すと空文字列が返ります |
\, /) before writing to disk; some authoring tools store relative paths in the name.
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;