PDF ExplainedApril 2, 20265 min read

What Is JavaScript in PDF? Uses, Risks, and Security

PDFs can execute JavaScript for calculations, validation, and dynamic behavior. Learn what PDF JavaScript can and cannot do, and the security implications.

PDF supports JavaScript execution within the document — the same language used on websites, but in a sandboxed environment within the PDF viewer. PDF JavaScript (formally called ECMAScript, standardized in PDF 1.3) enables interactive features: field validation, automatic calculations, show/hide conditional fields, and custom interfaces. It also represents a security surface area that has historically been exploited in malicious PDFs.

What PDF JavaScript Can Do

  • Form validation: validate field input (is this a valid date? is this number in range?) on key press or tab-out
  • Calculations: auto-compute fields (sum line items, compute tax, calculate age from birthdate)
  • Show/hide fields: conditionally display fields based on the values of other fields
  • Field formatting: automatically format numbers as currency, dates as "MM/DD/YYYY", or phone numbers as "(555) 555-1234"
  • Document events: run scripts on document open, page view, field focus, button click
  • App object access: limited access to the Acrobat application object — can read the username, open other files, send data to servers, play sounds

What PDF JavaScript Cannot Do (In Sandboxed Environments)

Modern PDF viewers run JavaScript in a restricted sandbox: no direct file system access beyond specific allowed paths, no arbitrary process execution, no unrestricted network access, limited DOM/UI manipulation. Browsers' built-in PDF viewers (Chrome, Firefox) execute little or no PDF JavaScript — they render forms statically and may not run any scripts. The full JavaScript environment is only available in Adobe Acrobat/Reader.

Security Risks

PDF JavaScript has been the vector for numerous high-profile exploits. Vulnerabilities in Acrobat's JavaScript engine have allowed: arbitrary code execution when a malicious PDF is opened (historically via heap spray and buffer overflow in the JS engine), data exfiltration via network requests triggered on document open, and tracking via URL loading when a PDF is opened (the server logs the request, revealing the recipient opened the file and their IP address). Adobe has substantially hardened the JavaScript sandbox in recent versions, and browsers' PDF viewers largely ignore JavaScript.

Disabling PDF JavaScript

In Adobe Acrobat Reader: Edit → Preferences → JavaScript → uncheck "Enable Acrobat JavaScript." This disables all JavaScript execution in PDFs. For enterprise deployments, this is often set as a policy. If you need JavaScript for forms but want to limit risks: keep Acrobat updated (most exploits target old versions), only enable JavaScript in PDFs from trusted sources, and consider using Enhanced Security mode which sandboxes JavaScript more aggressively.

Try Edit Pages Now — Free

Browser-based, private, and instant. No account or software required.

Open Edit Pages
Report Bug
Send Feedback
Feature Request