PDFiumPas 文件

AttachmentName 屬性

此 API 條目保留識別符號、簽名、程式碼塊和 PDF 術語的原始形式
元件: TPdf  ·  單元: PDFium
傳回文件 EmbeddedFiles 名稱樹中指定從 0 起算索引的嵌入檔案所登錄的 Unicode 檔名

語法

property AttachmentName[Index: Integer]: WString; // read only

說明

每個 PDF 附件都會在其檔案規格字典中帶有對應的檔名 — 通常是作者磁碟上當初看到的原始檔名(例如 contract.docxsource-data.csv)。AttachmentName 會將這個名稱以 WString 形式公開,方便在 UI 中顯示、作為建議的另存路徑,或依副檔名比對

回傳字串會從 PDF 的 UTF-16BEPDFDocEncoding 儲存格式解碼,因此非 ASCII 名稱(中文、西里爾字母、帶重音的拉丁字母)都能正確往返。若原作者只留下鍵值項目,卻沒有明確的 /F/UF 檔名,則會回傳空字串

此屬性為唯讀。此 API 不提供重新命名附件;若你需要變更檔名,請先用 DeleteAttachment 刪除該槽位,再用 CreateAttachment 重新建立,然後透過 Attachment 重新指定位元組

參數

IndexInteger。附件位置從 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;

另請參閱

Attachment, AttachmentCount, AttachmentType, CreateAttachment, DeleteAttachment