PDFium Delphi Component Docs

ReadAttachmentMetadata 方法

元件: TPdf  ·  單元: PDFium
一次性讀取文件層級內嵌附件的中繼資料,而不擷取任何承載位元組

語法

function ReadAttachmentMetadata(MaxAttachments: Integer = 10000): TPdfAttachmentMetadataArray;

MaxAttachmentsInteger。可擷取的附件項目數量上限;必須大於零,否則會引發 EPdfError;預設為 10000
ResultTPdfAttachmentMetadataArray。每個附件一個 TPdfAttachmentMetadata 記錄:Index、Name、Description、MimeType、Relationship(/AFRelationship 名稱,項目不存在或缺少匯出時為空字串)、Size 與 Readable

說明

在單一原生過程中列舉已載入文件的 EmbeddedFiles 樹狀結構,並為每個項目傳回一個 TPdfAttachmentMetadata 記錄。只讀取描述性的值,承載位元組仍保留在檔案中,因此列出含有多個大型附件的文件不會耗用任何承載記憶體

Index 欄位與 Attachment、AttachmentName 及其他附件索引子使用的以零為基底之索引一致,因此列出的項目稍後可透過同一個索引位置擷取

Readable 回報原生端是否能開啟承載;Size(以位元組為單位,Int64)只會為可讀取的項目填入。無法讀取的項目仍會出現在陣列中,讓索引與文件保持對齊

此呼叫會在算繪鎖定下執行,並要求必須已載入文件;MaxAttachments 小於或等於零時會引發 EPdfError

備註

範例

var
  Meta: TPdfAttachmentMetadata;
begin
  Pdf1.FileName := 'with-attachments.pdf';
  Pdf1.Active := True;
  for Meta in Pdf1.ReadAttachmentMetadata do
    Memo1.Lines.Add(Format('%d: %s (%s, %d bytes, readable=%s)',
      [Meta.Index, Meta.Name, Meta.MimeType, Meta.Size,
        BoolToStr(Meta.Readable, True)]));
end;

另請參閱

ExtractAttachmentsToStreams, Attachment, AttachmentCount, AttachmentName