THotPDF.RegisterDocumentJavaScript

THotPDF

 

AcroForm Support

Registers a document-level named JavaScript function in the Catalog /Names /JavaScript name tree (ISO 32000-1 §7.7.4.4 + §12.6.4.16). AcroForm widget actions, document-open actions, and other JavaScript bodies can invoke the registered function by name through the viewer’s JavaScript engine (Adobe Acrobat, Foxit, and other compatible viewers).

 

Delphi 구문:

procedure RegisterDocumentJavaScript(const Name, Body: AnsiString);

 

매개변수

이름은 JS source가 name tree에 저장되는 unique key입니다. PDF 1.7 §7.9.6에 따라 case-sensitive입니다. Empty 이름은 raise합니다

Body is the raw JavaScript source. HotPDF does not parse or validate the JS – the caller is responsible for syntactic correctness. Typical callers pass a complete function declaration (function GreetUser() { app.alert("hello"); }). Empty Body raises.

 

설명

Each call adds a (key, indirect dict) pair to the Catalog /Names /JavaScript name tree at EndDoc time. Each registered Body becomes its own indirect << /S /JavaScript /JS (body) >> dict, ready to be referenced by name from any other action or JS context. Useful for sharing a library of validation, formatting, or calculation helpers across many widgets without duplicating the source in each /A action.

Registering the same 이름 twice raises so callers do not silently lose their first definition.

 

Compliance gates

비어 있지 않은 모든 PDFACompliance setting에서 raise합니다(ISO 19005-1 §6.6.1 / ISO 19005-2 §6.5.1 / ISO 19005-3 §6.5.1은 모든 PDF/A level에서 JavaScript action을 금지). 비어 있지 않은 모든 PDFXCompliance setting에서도 raise합니다(ISO 15930 prepress workflow는 interactive scripting을 거부). 필요하면 document Version을 PDF 1.3으로 자동 bump합니다. 선택한 version이 PDF 1.3보다 오래되었고 StrictVersionLock이 설정된 경우 거부합니다

 

Example

PDF := THotPDF.Create(nil);
PDF.FileName := 'form.pdf';
PDF.BeginDoc;
PDF.RegisterDocumentJavaScript('GreetUser',
  'function GreetUser() { app.alert("Hello"); }');
PDF.RegisterDocumentJavaScript('ValidateNumber',
  'function ValidateNumber(v) { if (isNaN(v)) app.alert("Not a number"); }');
// ... AcroForm widget /A action can then call: ValidateNumber(this.value);
PDF.EndDoc;

 

Availability

HotPDF v2.119.14. PDF 1.3+ feature; HotPDF auto-bumps the document Version unless StrictVersionLock is set.

 

참조: AcroForm Support, THPDFActionScriptType