How to Add the Stamped PDF File Name to an Acrobat Dynamic Stamp
Question details
The user needs a custom dynamic stamp to automatically display the file name of the PDF document being stamped, rather than displaying the file name of the stamp template itself.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating or modifying a dynamic stamp in a PDF editor to include custom JavaScript that retrieves document metadata.
- Observed behavior
- When using typical scripts like 'this.documentFileName', the stamp displays its own source file name instead of the target document's file name.
Ensure you have access to Adobe Acrobat's form editing tools and have already set up a base dynamic stamp file with a text field ready for JavaScript calculation.
Use the Correct JavaScript Reference for the Target Document
Apply a specific calculation script to the stamp's text field to fetch the target document's name using the correct object hierarchy.
In Adobe Acrobat, dynamic stamps operate from within their own hidden PDF files. If you use a standard document-level script, it will reference the stamp's source file. To access the document currently being stamped, you must navigate the event object's source tree.
Locate and open your custom dynamic stamp PDF file in Adobe Acrobat. This is the background file where your stamp templates are stored.
Enter 'Prepare Form' mode. Right-click the text field where you want the file name to appear, and select 'Properties'.
Navigate to the 'Calculate' tab inside the Properties window. Select the 'Custom calculation script' radio button and click 'Edit'.
Enter the following exact script into the editor: `event.value = event.source.source.documentFileName;` and click OK.
Save your stamp file and close it. Open a different PDF document and apply your newly updated dynamic stamp to verify it pulls the correct file name.

Easily Add and Manage PDF Stamps with WPS Office
If you are looking for a straightforward way to stamp documents without managing complex JavaScript codes, WPS PDF provides an intuitive interface for applying pre-designed, dynamic, and custom image stamps directly to your files.
- 1. Open the PDF: Launch WPS Office and open the PDF document you need to stamp.
- 2. Navigate to the Comment Tab: Click on the 'Comment' tab located in the top ribbon menu to access annotation tools.
- 3. Select the Stamp Tool: Click the 'Stamp' icon. A drop-down menu will appear showing standard business stamps, sign-here tags, and dynamic stamps featuring the current date and time.
- 4. Apply and Resize: Click the desired stamp and then click anywhere on your document to place it. You can drag the corners to resize it perfectly to your needs.

Frequently Asked Questions
Can I remove the '.pdf' extension from the stamped file name?
Yes. You can modify your JavaScript to replace or split the string. For example: `var name = event.source.source.documentFileName; event.value = name.replace('.pdf', '');` will remove the extension before displaying it.
Why does my dynamic stamp show a blank field when I first create it?
When editing the stamp file itself, `event.source.source` is null because the stamp is not being applied to another document yet. The field will appear blank or show an error during creation, but will work properly once applied to a target PDF.
Do JavaScript dynamic stamps work on mobile PDF viewers?
Most mobile PDF viewers have limited or no support for custom JavaScript calculation scripts. Stamps relying on complex scripting should generally be applied on desktop applications.




