How to Retrieve the Page Count of Another PDF in a PDF Form
Question details
The user wants a PDF production run-sheet form to automatically extract and populate the filename and page count of an externally selected PDF file.

- Product
- Device & OS
- not provided
- Scenario
- Filling out a production run-sheet form that requires metadata from another PDF file, preferably without manual inspection.
- Observed behavior
- Standard secure file-selection dialogs cannot automatically inspect another PDF due to JavaScript sandbox limitations.
Keep in mind that standard PDF JavaScript operates in a restricted sandbox. Automatically reading external file properties requires elevated application privileges or folder-level trusted scripts to bypass security blocks.
Use a Folder-Level Trusted JavaScript Function
Implement a trusted application-level script to grant your PDF form the privileges needed to read external document properties.
By default, standard PDF form JavaScript has limited access to the local file system. A secure file-selection dialog cannot generally inspect another PDF automatically. To achieve this workflow, you must use a trusted script stored in the application's privileged directory.
Create a new text file and write a JavaScript function wrapping your file-reading code inside 'app.trustedFunction'. This allows the script to securely access external PDF objects.
Save the file with a .js extension and place it into your PDF reader's global application JavaScripts folder. This directory path varies depending on your specific PDF software and operating system.
Close and reopen your PDF software so that it compiles and loads the new application-level script into memory.
Open your production run-sheet form, right-click the file-selection button, and access its Properties. Under the Actions tab, select 'Run a JavaScript' and input the command to call your newly trusted function.

Manually Inspect and Input PDF Metadata
If setting up trusted scripts across multiple devices is not feasible, use the standard document properties menu to locate the information quickly.
Easily Manage PDF Forms and Document Metadata with WPS Office
While automated cross-PDF scripting requires complex trusted configurations, WPS PDF offers a highly efficient, user-friendly interface to quickly check document properties and fill out production forms side-by-side.
- 1. Open Your PDF Form: Launch WPS Office and open your production run-sheet PDF form.
- 2. Open the Reference Document: Open the secondary PDF document in a new tab within the same WPS PDF window for easy access.
- 3. Check Document Properties: Click 'Menu' in the top left corner, then navigate to 'Document Properties' to view the exact page count and file path.
- 4. Input the Details: Switch back to your run-sheet form tab and input the verified filename and page count into the form fields.
- 5. Save Your Form: Click the 'Save' icon or press Ctrl+S to save the completed production form.

Frequently Asked Questions
Why can't a standard PDF form button browse and read another PDF's page count automatically?
Standard PDF form JavaScript operates within a strict security sandbox. To prevent malicious scripts from accessing private files on a user's computer, document-level scripts are generally restricted from reading properties of external files without explicit application-level privileges.
Can I use an external script instead of PDF JavaScript to automate this?
Yes. You can use external programming languages like Python (with libraries such as PyPDF2) or batch scripts to extract the page count and filename of a PDF, and then generate an FDF file to automatically populate your run-sheet form.
How do I add a 'Run a JavaScript' action to a PDF form button?
In your PDF form editor, right-click the button and select 'Properties'. Go to the 'Actions' tab, choose 'Mouse Up' as the trigger, select 'Run a JavaScript' from the action dropdown, click 'Add', and then type or paste your script code.




