PDFium Component Docs

AttachmentName プロパティ

この API エントリでは識別子、シグネチャ、コードブロック、PDF 用語を元の表記のまま保持します。
コンポーネント: TPdf  ·  ユニット: PDFium
文書 EmbeddedFiles name tree の指定した 0 基準インデックスにある埋め込みファイルに登録された Unicode file name を返します

構文

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.

パラメータ

IndexInteger. Zero-based attachment position. Must be in [0, AttachmentCount - 1]。範囲外の index を渡すと空文字列が返ります

備考

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;

関連項目

Attachment, AttachmentCount, AttachmentType, CreateAttachment, DeleteAttachment