PDFium Delphi Component Docs

GetAttachmentDictionaryValue 方法

元件: TPdf  ·  單元: PDFium
讀取文件層級內嵌附件之檔案規格字典的單一鍵,並回報值類型與解碼後的字串

語法

function GetAttachmentDictionaryValue(Index: Integer; const Key: WString): TPdfDictionaryValue;

IndexInteger。內嵌附件的自零起算索引,範圍為 0 .. AttachmentCount - 1。超出範圍的索引會引發 EPdfError
KeyWString。要從附件檔案規格字典讀取的項目名稱,例如產生端應用程式寫入的自訂鍵
ResultTPdfDictionaryValue。Kind 一律攜帶原生值類型;對 pdvkString 與 pdvkName 值會填入 StringValue,且 HasScalarValue 為 True

說明

EmbeddedFiles 樹的每個項目都是一個 PDF 檔案規格字典,附件的私有中繼資料就存放在這個字典裡。此呼叫探查該字典的單一鍵並傳回 TPdfDictionaryValue:值類型由原生類型查詢解碼而來,當項目持有字串或名稱時,會讀取文字並放進 StringValue 傳回,同時設定 HasScalarValue

其他類型的值 — 數值、布林、陣列、巢狀字典、串流 — 只透過 Kind 回報;HasScalarValue 維持 False,因為只有字串與名稱項目會被解碼。請先用 AttachmentHasKey 測試鍵是否存在

此呼叫要求已載入文件與有效的附件索引。當字串項目的純文字已經足夠且不在乎類型時,請使用 GetAttachmentStringValue;要寫回字串項目則使用 SetAttachmentStringValue

備註

範例

var
  Value: TPdfDictionaryValue;
begin
  if Pdf1.AttachmentHasKey(0, 'SourceApp') then
  begin
    Value := Pdf1.GetAttachmentDictionaryValue(0, 'SourceApp');
    if Value.HasScalarValue then
      Memo1.Lines.Add('Source: ' + Value.StringValue);
  end;
end;

另請參閱

AttachmentHasKey, GetAttachmentStringValue, SetAttachmentStringValue, Attachment