property JavaScriptActionCount: Integer; // read only
Returns the number of JavaScript actions declared at the document level —
typically entries under the catalog’s /Names /JavaScript name tree
(PDF 1.7 spec section 12.6.4.16) plus document-level OpenAction,
DA, WC, WS, DS, WP,
DP entries when their action dictionaries carry a JS stream.
Field-level and annotation-level scripts are not included; those live on the
annotations or AcroForm field dictionaries.
The value is 0 when the document does not load, when Active
is False, or when the PDF simply contains no document-level scripts. Use
JavaScriptAction[Index] to retrieve a single entry as a
TPdfJavaScriptAction record (Name + Script source) or
JavaScriptActions to materialise the whole array in one call.
Reading this property is cheap — PDFium only walks the name tree without executing any script. PDFiumVCL does not evaluate JavaScript; the strings returned are pure inspection data, useful for forensic analysis, removing scripts before redistribution, or surfacing a “Document contains JavaScript” warning to the user.
JavaScriptActions when only a count or single entry is needed.Name entries are valid — PDF allows unnamed action
dictionaries (e.g. OpenAction). Do not rely on Name being unique either.
// Warn the user if the PDF carries embedded JavaScript.
if Pdf1.JavaScriptActionCount > 0 then
if MessageDlg('This document contains JavaScript. Open anyway?',
mtWarning, [mbYes, mbNo], 0) = mrNo then
Pdf1.Active := False;