THotPDF.AddLoadedDocumentJavaScript Method
Adds a named script entry to the named JavaScript collection of the loaded PDF document, making it execute automatically at the document level
Declaration
procedure AddLoadedDocumentJavaScript(const AName, ABody: AnsiString);
Unit
HPDFDoc
Parameters
| Name | Purpose |
|---|---|
AName | The unique name of the script entry, used to identify and reference this script in the name tree; it can also be deleted by name via RemoveLoadedJavaScript |
ABody | The complete body code of the JavaScript script, executed by the PDF reader when the document is opened |
Usage notes
- 若文档已存在同名脚本,此方法将覆盖现有条目,而不会创建重复项
- The execution of document-level JavaScript relies on the PDF reader's support for scripts; Adobe Acrobat has the most complete support, whereas other readers may ignore this script
- If the script code contains special characters, they must undergo PDF string escaping; it is recommended to verify the script logic in Acrobat before embedding