Other PDF Issues

Run an Acrobat JavaScript Merge Script from a Toolbar Button

Khadija KhanKhadija Khan Nov 24, 2026 868 views

Question details

The user wants to run an Acrobat JavaScript PDF merge script without repeatedly opening the console and pasting the code.

Run an Acrobat JavaScript Merge Script from a Toolbar Button
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Run an existing PDF merge script from a custom tool or keyboard shortcut.
Observed behavior
The desired workflow is to launch the merge script directly instead of pasting and executing it in the JavaScript console each time.
Before you start

Confirm that your Acrobat edition supports the JavaScript APIs used by the merge script, and locate the folder-level JavaScripts directory for your Acrobat version and operating system. Review the script's file paths and permissions before making it available as a toolbar command.

Solution 1Recommended

Register the merge script as an Acrobat toolbar button

Use a folder-level script to add a button that runs the merge command without opening the console.

Operations such as file access, app.openDoc, and app.newDoc can require a trusted context. Use Acrobat's trusted-function mechanism for privileged operations rather than weakening security settings.

Store a document's numPages value before closing it. Accessing the document after it is closed can cause a DeadObject error.

1
Create a folder-level script

Place the merge code in a .js file in Acrobat's documented folder-level JavaScripts directory. Define a function that runs the merge and checks the required file paths.

2
Handle privileged operations

Wrap operations that require elevated privileges in an app.trustedFunction and use app.beginPriv() and app.endPriv() as required by the Acrobat JavaScript API. Ensure app.endPriv() runs even if an operation fails.

3
Register the button

In the same .js file, call app.addToolButton with a unique button name and a cExec action that invokes the merge function. Set an informative tooltip so the button is easy to identify.

4
Restart and run

Restart Acrobat to load the folder-level script, then select the custom button on the toolbar to run the merge. If the button is not visible, check the toolbar configuration and JavaScript console for errors.

Register the merge script as an Acrobat toolbar button
Keyboard shortcut limitation: Acrobat does not provide a general keyboard shortcut for running arbitrary scripts. A custom toolbar button provides a direct way to launch this script.
Free Microsoft Office alternative

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 documents. Its format compatibility helps make moving everyday files from Microsoft Office straightforward; it does not run or repair Acrobat JavaScript tools.

Open and work with PDF documents in a familiar workspaceCompatible with Microsoft Office formats including DOCX, XLSX, and PPTXLightweight application for everyday document tasksFamiliar interface makes it easier to move from Microsoft Office
microsoft office alternative - wps office

Frequently Asked Questions

Can I assign a keyboard shortcut to any Acrobat JavaScript?

Acrobat does not offer a general shortcut for arbitrary scripts. For this merge workflow, register a custom toolbar button with app.addToolButton instead.

Why does my merge script need a trusted function?

Some file-access and document operations are security-restricted. Put operations that require privilege inside an app.trustedFunction and follow Acrobat's rules for app.beginPriv() and app.endPriv().

Why does the script report a DeadObject error after closing a PDF?

A closed document object can no longer be accessed. Read and store values such as doc.numPages before calling the document's close method.

Can a script execute code by writing it to the JavaScript console?

No. A script can display text in the console, but writing code there does not execute it. Register the merge function as a toolbar command instead.