Troubleshoot an Acrobat JavaScript Button That Cannot Add PDF Attachments
Question details
Determine why an Acrobat JavaScript button does not add a selected file as a PDF attachment annotation.

- Product
- Adobe Acrobat JavaScript
- Device & OS
- not provided
- Scenario
- A custom Add PDF button should open a file browser and create a FileAttachment annotation for the selected file.
- Observed behavior
- Clicking the button appears to do nothing.
Open the PDF and locate the Add PDF button's JavaScript in Acrobat. Identify the button action and any custom dialog code so you can test the file browser and annotation creation separately.
Isolate the Acrobat file browser and attachment annotation
Use a minimal test to identify whether the button, file selection, or annotation creation is failing.
Open the button's properties in Acrobat and check the Actions tab for the JavaScript associated with the click. Temporarily remove unrelated custom dialog code from a test version of the script.
Open the Acrobat JavaScript console, clear existing messages, and click the Add PDF button. Check for errors or a test message confirming that the button action ran.
Run a minimal test of app.browseForDoc() from the relevant button action. Select a file and inspect the returned result in the JavaScript console to confirm that it contains a usable file path.
Test addAnnot() separately with a known file path and the properties required for a FileAttachment annotation. Check the JavaScript console and the PDF page to see whether the annotation is created.
Once both tests work, add the custom dialog and remaining code back in stages. Click Add PDF after each change to identify the operation that causes the failure.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office files. Its format compatibility helps make migration straightforward, although it does not troubleshoot Acrobat JavaScript.

Frequently Asked Questions
How can I tell whether the Add PDF button runs its script?
Check the button's Actions tab in Acrobat to confirm that a JavaScript action is assigned. Add a temporary test message, then click the button and check the JavaScript console.
What should I check if the file browser does not open?
Test app.browseForDoc() on its own from the button action and inspect the Acrobat JavaScript console for errors. Also check whether the operation is restricted by the execution context or security settings.
What if I can select a file but no attachment appears?
Inspect the result returned by app.browseForDoc(), then test addAnnot() separately with a known file path and the required FileAttachment properties. Check the console for errors and the target PDF page for the annotation.
Can WPS Office fix an Acrobat JavaScript error?
No. Troubleshoot Acrobat-specific JavaScript in Acrobat using its button properties, JavaScript console, and documentation. WPS Office is an alternative for general PDF and Office file work.




