How to Use insertPages as a Trusted Acrobat Folder-Level Function
Question details
The user needs to insert a PDF page using the insertPages method triggered by a form control.

- 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.
Close your PDF application and ensure you have administrative permissions to navigate to the software's installation directory and save new script files.
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.
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).
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).
Close and reopen your PDF software. This triggers the application initialization event, loading your custom trusted function into the environment.
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();

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. Open your PDF file: Launch WPS Office and open the PDF document where you want to add new pages.
- 2. Navigate to the Page tab: Click on the 'Page' tab in the top ribbon menu to access page management tools.
- 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.

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.




