property Active: Boolean; // default False
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 laddar automatiskt om dokumentet från den nya sökvägen, vilket är det rekommenderade sättet att växla mellan PDF-filer i en enda TPdf-instans.
Om filen inte kan öppnas (fel sökväg, fel lösenord, skadad PDF eller ett XFA-only-formulär som inte stöds) kastas en EPdfError undantag. Omslut tilldelningen i ett try/except-block för smidig felhantering och granska E.Message for the PDFium error description.
Active becomes True — see LoadLibrary if you need to pre-load it from a custom path.PdfView1.Pdf := Pdf1 first; then assign Pdf1.Active := True för att öppna dokumentet och rendera den första sidan.Active := False) invalidates every record returned earlier from indexed properties (Annotation, Bookmark, FormFieldInfo, etc.) — do not retain them across an open/close cycle.
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;