PDFiumVCL 文档

Active property

此 API 条目保留标识符、签名、代码块和 PDF 术语的原始形式。
Component: TPdf  ·  Unit: PDFium
Opens or closes the selected PDF document.

Syntax

property Active: Boolean; // default False

Description

Setting Active to True opens and loads the PDF document specified by FileName, using Password if the document is encrypted. When set to False, the document is closed and all associated PDFium resources (pages, fonts, form handles, text pages) are freed.

You can also call LoadDocument directly instead of toggling this property. Assigning FileName while Active is already True automatically reloads the document from the new path, which is the recommended way to switch between PDFs in a single TPdf instance.

If the file cannot be opened (wrong path, bad password, corrupt PDF, or unsupported XFA-only form) an EPdfError exception is raised. Wrap the assignment in a try/except block for graceful error handling, and inspect E.Message for the PDFium error description.

Remarks

Example

Pdf1.FileName := 'C:\docs\report.pdf';
Pdf1.Password := ''; // leave empty if not encrypted
try
  Pdf1.Active := True;
  ShowMessage('Pages: ' + IntToStr(Pdf1.PageCount));
except
  on E: EPdfError do
    ShowMessage('Cannot open: ' + E.Message);
end;

See Also

FileName, Password, LoadDocument, PageCount, LoadLibrary, CreateDocument