Embed field JavaScript (beta)⚓︎
Info
These beta features and their documentation are subject to change. Use with caution; they may be modified, rolled back, or fail in some PDF forms.
Warning
Do NOT trust user input; always sanitize it. Although PDF JavaScript runs in a sandbox, arbitrary execution is dangerous and can lead to remote code execution vulnerabilities.
This documentation uses this PDF as an example.
PDF form fields can execute JavaScript during interactions if supported by the viewer. PyPDFForm provides APIs to embed scripts into form fields.
For example, this snippet embeds a script that triggers an alert when the test field is hovered:
Tip
Please refer to this link for JavaScript that can be executed in PDF forms.
Execute JavaScript on hover⚓︎
Set the on_hovered_over_javascript attribute to run code when a field is hovered over:
Execute JavaScript on hover off⚓︎
Set the on_hovered_off_javascript attribute to run code when the mouse moves away from a field:
Execute JavaScript on mouse pressed⚓︎
Set the on_mouse_pressed_javascript attribute to run code when a mouse button is pressed within a field:
Execute JavaScript on mouse released⚓︎
Set the on_mouse_released_javascript attribute to run code when a mouse button is released within a field:
Execute JavaScript on focus⚓︎
Set the on_focused_javascript attribute to run code when a field gains focus:
Execute JavaScript on blur⚓︎
Set the off_focused_javascript attribute to run code when a field loses focus: