PDFium Delphi Component Docs

Active property

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; it raises EPdfError on failure. FileName and Password can only be assigned while the component is inactive, so switching documents on one TPdf instance means setting Active to False, assigning the new path, and setting Active to True again

Setting Active to True does not raise when the file cannot be opened (wrong path, bad password, corrupt PDF, or unsupported XFA-only form): the component simply stays inactive. Check Active after the assignment and read LastLoadReport, whose Status is plsFailed and whose ErrorMessage describes the failure

Remarks

Example

Pdf1.FileName := 'C:\docs\report.pdf';
Pdf1.Password := ''; // leave empty if not encrypted
Pdf1.Active := True;
if Pdf1.Active then
  ShowMessage('Pages: ' + IntToStr(Pdf1.PageCount))
else
  ShowMessage('Cannot open: ' + Pdf1.LastLoadReport.ErrorMessage);

See Also

FileName, Password, LoadDocument, PageCount, LoadLibrary, CreateDocument