PDF Editing Issues

How to Add the Stamped PDF File Name to an Acrobat Dynamic Stamp

Maira MehtabMaira Mehtab Nov 5, 2026 869 views

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.

How to Add the Stamped PDF File Name to an Acrobat Dynamic Stamp
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Stamp Source File

Locate and open your custom dynamic stamp PDF file in Adobe Acrobat. This is the background file where your stamp templates are stored.

2
Access Field Properties

Enter 'Prepare Form' mode. Right-click the text field where you want the file name to appear, and select 'Properties'.

3
Set the Calculation Script

Navigate to the 'Calculate' tab inside the Properties window. Select the 'Custom calculation script' radio button and click 'Edit'.

4
Input the Code

Enter the following exact script into the editor: `event.value = event.source.source.documentFileName;` and click OK.

5
Save and Test

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.

Use the Correct JavaScript Reference for the Target Document
Why 'this.documentFileName' Fails: The 'this.documentFileName' property inside a stamp script specifically returns the stamp template's file name. The 'event.source.source' structure is required to point back to the parent application window holding the target PDF.

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. 1. Open the PDF: Launch WPS Office and open the PDF document you need to stamp.
  2. 2. Navigate to the Comment Tab: Click on the 'Comment' tab located in the top ribbon menu to access annotation tools.
  3. 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. 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.
Extensive library of pre-designed dynamic and standard stampsEasily upload custom images and signatures without codingFully compatible with standard Adobe PDF formatsLightweight, fast, and available across Windows, Mac, and mobile platforms
microsoft office alternative - wps office

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.