PDFium Delphi Component Docs

AttachmentName 屬性

元件: TPdf  ·  單元: PDFium
傳回文件 EmbeddedFiles 名稱樹中指定從 0 起算索引的嵌入檔案所登錄的 Unicode 檔名

語法

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 重新指派位元組

參數

IndexInteger。以 0 為基底的附件位置。必須在 [0, AttachmentCount - 1] 範圍內。傳入超出範圍的索引會傳回空字串

備註

範例

var
  I: Integer;
  FileName: string;
begin
  Pdf1.FileName := 'package.pdf';
  Pdf1.Active := True;
  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