How to Show a Custom JavaScript Dialog Once for Multiple PDF Files in Adobe Acrobat
Question details
The user needs a custom JavaScript dialog in Adobe Acrobat Pro's Action Wizard to appear only once, reusing the user's input for all files in a batch process instead of prompting per file.

- Product
- Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- Running a batch script using the Action Wizard on multiple PDF documents.
- Observed behavior
- The Action Wizard script prompts the user with the custom dialog for every single file in the batch, rather than asking once and applying the settings globally.
Ensure you have Adobe Acrobat Pro installed with access to the Action Wizard, and possess basic familiarity with modifying JavaScript code for Acrobat.
Use a Global Variable to Store Dialog Settings
By assigning your custom dialog inputs to a global variable, you can instruct the script to bypass the prompt for subsequent files in the batch execution.
In Adobe Acrobat Pro, the Action Wizard executes the assigned JavaScript independently for each document. To share data across these separate script executions, you must use the `global` object. By checking if a specific global variable exists, you can prompt the user once and then reuse their inputs for the rest of the batch.
At the beginning of your Action Wizard script, add a condition like `if (global.myWatermarkData == null)` to check if the settings have already been captured in a previous iteration.
Inside the condition, add the code to display your custom dialog and save the returned values directly to the global variable (e.g., `global.myWatermarkData = dialogResult;`).
Outside of the condition, write the execution logic that applies the values stored in the global variable to the current PDF document.
To prevent the settings from being accidentally applied to a future batch, manually delete the global variable using `delete global.myWatermarkData;` at the very end of your batch process logic, or be prepared to restart Acrobat.

Batch Process PDFs Easily with WPS Office
Instead of writing complex JavaScript to manage custom dialogs and global variables, you can use WPS Office's built-in PDF tools to batch process multiple documents—such as adding watermarks—in just a few clicks.
- 1. Open WPS PDF: Launch WPS Office on your computer and open the WPS PDF application.
- 2. Access Batch Tools: Navigate to the 'Tools' or 'Batch' tab and select the 'Batch Add Watermark' feature (or whichever batch tool you need).
- 3. Add Your PDF Files: Click 'Add Files' or simply drag and drop all the PDF documents you want to process into the batch list.
- 4. Configure Settings Once: Set up your custom watermark text, image, and positioning within the unified settings dialog box.
- 5. Run the Batch: Click the 'Start' button to automatically apply your single configuration across all selected PDF files.

Frequently Asked Questions
Why does the Action Wizard run the script for every single file?
The Action Wizard treats each document in a batch process as an independent execution environment. It automatically re-runs the entire script for every file, which is why standard local variables and dialogs reset and reappear each time unless stored globally.
How do I define a global variable in Acrobat JavaScript?
You define a global variable by prefixing your variable name with the `global` object, such as `global.mySettings = value;`. This allows the data to persist in the application's memory across different document script executions.
What happens if I forget to delete the global variable?
If the global variable is not explicitly deleted at the end of the script execution, it will remain in Acrobat's memory. The next time you run the Action Wizard, it will bypass the dialog entirely and apply the outdated settings from your previous session. Restarting the Acrobat application will completely clear the variable.
Can I use this JavaScript global variable method for tasks other than watermarking?
Yes, you can use global variables to store user input for any batch processing task in Adobe Acrobat, such as setting custom document metadata, applying specific security permissions, or defining automated page extraction parameters.




