Fix the Document Is Not Defined Error in Acrobat JavaScript
Question details
The user needs to resolve a document is not defined error in an Acrobat PDF form script.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Running JavaScript that accesses form fields or performs other actions in a PDF.
- Observed behavior
- Acrobat reports ReferenceError: document is not defined when the script uses browser-specific document methods.
Open the PDF in Acrobat and locate the script and exact error message. Check the form field name and capitalization in Prepare a Form before changing the code.
Replace browser DOM field access with Acrobat JavaScript
Use this approach when a PDF form script calls document.getElementById or another browser DOM method.
Acrobat JavaScript does not provide the browser DOM. JavaScript is case-sensitive, so use the exact method name getField and the exact PDF field name.
In Acrobat, open Prepare a Form, right-click the relevant field, and select Properties. On the Actions tab, select the JavaScript action and click Edit.
Replace a browser lookup such as document.getElementById("FieldName") with this.getField("FieldName") in a script where this refers to the PDF document.
In Prepare a Form, inspect the field's name and make sure it exactly matches the text passed to getField. A nonexistent field returns null.
Save the script and PDF, then perform the form action again. Check the JavaScript debugger for any remaining error and its line number.

Check the rest of the script for browser-only document calls
Use this if the error persists after correcting the field lookup or points to another line.
Use WPS Office for Everyday PDF and Office Tasks
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office files. Its format compatibility makes it easy to move between common document workflows. It does not repair Acrobat JavaScript.

Frequently Asked Questions
Why does document.getElementById fail in an Acrobat form?
Acrobat JavaScript does not provide the browser document object or DOM methods. Use this.getField("FieldName") when this refers to the PDF document.
How do I find the correct PDF field name?
Open Prepare a Form in Acrobat, select the field, and inspect its properties. Use the exact field name, including capitalization, in getField.
What if getField returns null?
Check that the field exists and that its name matches the name in this.getField("FieldName") exactly. Also confirm that this refers to the PDF document in the script's context.
Can another line cause the same document is not defined error?
Yes. Any browser-specific use of document, such as document.print(), can trigger it. Check the error line in Acrobat's JavaScript debugger and review the complete script.




