PDF Editing Issues

How to Use insertPages as a Trusted Acrobat Folder-Level Function

Adam DavisAdam Davis Nov 5, 2026 870 views

Question details

The user needs to insert a PDF page using the insertPages method triggered by a form control.

How to Use insertPages as a Trusted Folder-Level Function in PDF Forms
Product
PDF Editing Software
Device & OS
not provided
Scenario
Executing privileged JavaScript to dynamically insert a remote PDF page when a user interacts with a form button.
Observed behavior
Privileged methods like insertPages fail when called directly from a document-level script because they require trusted execution within an application initialization event.
Before you start

Close your PDF application and ensure you have administrative permissions to navigate to the software's installation directory and save new script files.

Solution 1Recommended

Install Privileged Code as an Application Startup Script

Since trusted functions require elevated privileges, you must define the function in a global folder-level script rather than directly inside the PDF document.

Adobe Acrobat and standard PDF specifications restrict methods like insertPages for security reasons. To use it securely, you must elevate privileges using app.beginPriv() and app.endPriv() inside a trustedFunction.

Crucially, trusted functions are only available during batch, console, and application initialization events. This means the script must be placed in the global JavaScripts folder to load when the application starts.

1
Create the folder-level JavaScript file

Open a plain text editor like Notepad. Write your function using app.beginPriv() and this.insertPages(), then register it globally using var Trusted_AddRemotePage = app.trustedFunction(AddRemotePage).

2
Save to the application JavaScripts folder

Save the text file with a .js extension (e.g., InsertPageScript.js). Move this file into the application's global JavaScripts directory (typically found under Program Files in the application's installation path).

3
Restart the PDF application

Close and reopen your PDF software. This triggers the application initialization event, loading your custom trusted function into the environment.

4
Call the function from your form control

Open your target PDF document. Right-click the form button, go to Properties, navigate to the Actions tab, and set a Run a JavaScript action that simply calls your registered function: Trusted_AddRemotePage();

Install Privileged Code as an Application Startup Script
Script Location: If you are unsure where the global JavaScript folder is located, you can open the PDF software's JavaScript console and execute app.getPath('user', 'javascript') or app.getPath('app', 'javascript') to find the exact directory path.
Simplify PDF Page Management

Insert PDF Pages Visually with WPS Office

If configuring application-level JavaScript trusted functions is too complex for your workflow, you can easily insert, merge, and manage PDF pages directly using the intuitive user interface of WPS Office without writing any code.

  1. 1. Open your PDF file: Launch WPS Office and open the PDF document where you want to add new pages.
  2. 2. Navigate to the Page tab: Click on the 'Page' tab in the top ribbon menu to access page management tools.
  3. 3. Insert the new page: Click 'Insert Page' and choose whether to insert a Blank Page or select 'From PDF' to browse and insert an external PDF file exactly where you need it.
No complex JavaScript or folder-level scripting requiredSeamlessly insert blank pages or merge remote PDF files instantlyFully compatible with standard PDF formats and formsLightweight, fast, and user-friendly interface
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a security error when calling insertPages directly from a button?

The insertPages method requires elevated privileges. Modern PDF software blocks document-level scripts from executing this method to prevent malicious code from modifying files without user consent. It must be wrapped in a trusted function.

Can I embed a trustedFunction directly inside my PDF document?

No. According to PDF API documentation, the app.trustedFunction method is only available during batch, console, and application initialization events. It cannot be defined within document-level scripts.

How do I share a PDF form that relies on a folder-level script with other users?

Because the trusted function resides in the application's local JavaScript folder, every user who needs to use the form control must manually install the corresponding .js file into their own local software installation directory.