PDFiumPas 說明文件

Title 屬性

此 API 頁面保留識別符號、簽名、程式碼區塊與 PDF 術語原樣
元件: TPdf  ·  單元: PDFium
回傳 PDF 文件資訊字典中 /Title 項目的值

語法

property Title: WString; // read only

說明

Title 會回傳文件宣告的標題,也就是 Acrobat 在應用程式標題列顯示的同一串文字,只要開啟 "Display document title in title bar" viewer preference 就會看到

這個值是透過 MetaText['Title'] 取得,內部會呼叫 PDFium 的 FPDF_GetMetaText 去讀文件資訊字典中的 /Title 項目(ISO 32000-1 § 14.3.3)

如果該項目不存在,或元件目前沒有啟用,這個屬性就會回傳空的 WString,它刻意和檔名基底不同,例如剛輸出的 quarterly-2026.pdf,仍然可以透過 /Title 宣告自己是 "Q1 2026 Financial Review"

這個屬性是唯讀,若要在建立時就寫入標題,請透過 FPDF_SetMetaText 搭配 Document handle,或直接寫入 XMP 中繼資料串流(dc:title

注意事項

實例

function EffectiveTitle(Pdf1: TPdf; const Fallback: string): string;
begin
  if not Pdf1.Active then
    Pdf1.Active := True;
  Result := Trim(Pdf1.Title);
  if Result = '' then
    Result := Fallback;
end;

// Use the document's own title for the form caption.
Caption := EffectiveTitle(Pdf1, ExtractFileName(Pdf1.FileName));

另請參閱

Author, Subject, Keywords, MetaText, CreationDate, Active