Copy link to clipboard
Copied
Hello,
I would like to create a dynamic stamp composed of three different fields. The first field should include the Name and Identifier in the format "Name (Identifier)" from the "Identity" section of Adobe preferences. The second field should display the current date, and the third field should show the name of the file on which the stamp is applied. Here is an example. I have already tried, but only the date is dynamic; the rest does not work, and I am getting error messages in the JavaScript console saying that I do not have the necessary permissions. This stamp should be able to work across multiple sessions. The goal is to copy and paste it onto several users' PCs in the stamp directory on the C drive or the hidden AppData folder of Adobe.
Thank you.
Copy link to clipboard
Copied
bonjour,
C'est beaucoup plus simple que ça, tu as juste besoin de ce script :
event.value=identity.name+" ("+identity.loginName+")";
this.getField("Date").value=util.printd("mm/dd/yy", new Date());
this.getField("Certificat").value=event.source.source.documentFileName.replace(/\.pdf$/i,"");
Ce qui donne avec le fichier joint :
@+
Copy link to clipboard
Copied
As mentioned previously in the thread, the conditional statements were included to avoid errors when the calculation runs before the stamp is applied and in case the file contained more than 1 stamp.
Copy link to clipboard
Copied
1. There are two ways to do this.
a) Open the stamp file and run the following script in the console: this.templates
b) Apply the stamp to a PDF, select the stamp and run the following script in the console: this.selectedAnnots[0].AP
https://youtu.be/DePWr_1lnYg?t=184
2) Yes. this.getField("File Name").value = app.repsonse("Enter file name:");
3) Make the stamp field a multiline text field.
4) By "lock", if you mean the locked check box in the appearance tab of the stamp properties is checked, you simply set the lock property of the stamp to true. Anybody can access the properties and uncheck the box. If you want the stamp to be locked so that there can be no user interaction with the stamp after it is placed, simply set the readOnly property to true. This can only be undone with a script. Having either of the settings executed automatically as the stamp is applied is proprietary information that I'm not willing to share here since most of the experts say it can't be done.
5. You'll have to either change the template name or the document Title (which is the category in the stamp menu). The template name mush begin with # or the stamp may only function once in a session.
Copy link to clipboard
Copied
Hi @Mystical_passion8499,
Thanks for reaching out and for sharing your use case with the community!
Creating a custom dynamic stamp that pulls the Name (Identifier) from the user’s Identity preferences, along with the current date and the file name, is a powerful but slightly nuanced task in Acrobat due to JavaScript security restrictions and session persistence. Here’s how you can approach this:
Create a dynamic stamp with three fields:
Name and Identifier from Edit > Preferences > Identity
Current Date
File Name of the PDF being stamped
Open Acrobat or any PDF editor.
Add form fields named:
userInfoField
dateField
fileNameField
Save the file as a single-page PDF.
You’ll need to add the following code inside the form fields (you can use a custom calculation script in each):
try {
var identityName = https://adobe.ly/3GtLxe3;
var identityLogin = identity.loginName;
if (!identityLogin) identityLogin = "NoID";
event.value = identityName + " (" + identityLogin + ")";
} catch (e) {
event.value = "Unknown User";
}
event.value = util.printd("dd-mmm-yyyy", new Date());
try {
event.value = this.documentFileName;
} catch (e) {
event.value = "Unknown File";
}
If you see messages like “not allowed due to security settings”, it’s due to Acrobat’s sandboxing of dynamic stamp scripts, especially when trying to access privileged objects like identity.
To make this work:
Use the app.getIdentityString() method only inside a dynamic stamp context.
Ensure your script is placed directly inside the dynamic stamp’s calculation script, not in a global or document-level script.
If you prefer one single text field for all values:
try {
var name = https://adobe.ly/3GtLxe3 || "Unknown";
var id = identity.loginName || "NoID";
var date = util.printd("dd-mmm-yyyy", new Date());
var fileName = this.documentFileName || "NoFile";
event.value = name + " (" + id + ")\n" + date + "\n" + fileName;
} catch (e) {
event.value = "Stamp Error: " + e.toString();
}
Once you save your dynamic stamp PDF, place it in the user’s stamp folder:
C:\Users\<username>\AppData\Roaming\Adobe\Acrobat\<version>\Stamps\
Acrobat will auto-load any valid stamp PDFs from this folder on the next launch.
Some Notes:
Ensure Acrobat is restarted after copying stamp files.
If the identity fields are blank, users may need to set their Identity under:
Edit > Preferences > Identity
This stamp can work across multiple sessions as long as users have Acrobat (not Reader in strict mode), and permissions allow access to Identity info.
Wait for more inputs form the experts.
~Tariq
Copy link to clipboard
Copied
Please upload the stamp file.
Copy link to clipboard
Copied
Thank you for your responsiveness. Here is the dynamic stamp with the authorization issues that I tried to create. I don't have Adobe Pro on my session, but I can do it on someone else's computer who has a Pro license. I would like to clarify that it should not be possible to change the identifier, as it is supposed to prove that the person logged into this session validated the document with the stamp.
Copy link to clipboard
Copied
So first, there is no script in the "Nom" field. The script in this field should be set as shown by Tariq.
The 3rd field, places the name of the stamp file in the field, not the name of the file being stamped.
The document object for the file being stamped is in the
even.source.source property
So the script should be
event.value = event.source.source.documentFileName.replace(/\.pdf$/,"");
BTW: Tariq did a fantastic write up. You should read it.
Copy link to clipboard
Copied
The identity object can only be accessed from a privileged context, or in a dynamic stamp environment. As soon as you close the field property window of a field to which you have added a calculation script, the calculation will run. Since this is not a privileged context and the calculation is running in a non-dynamic stamp environment, it will throw a security error. It won't throw an error when the script runs as part of the stamping process. To avoid this you should put the following condition on your script:
if(event.source.forReal)
{/* Your script */}
event.source.forReal is only true during the stamp process. In case you have more than one stamp in the same file (category) you should also add another condition that identifies the AP property of the stamp. While not necessary, I find it helpful for troubleshooting to have one calculation script for all fields instead of a separate calculation for each field. Here's the script using the tips above in a separate field created for the calculation only (with your other scripts removed):
if(event.source.forReal && event.source.stampName=="#FyKxg3RHkTARzoly-AusJA")
{
this.getField("Nom (Identifiant)").value=identity.name+" ("+identity.loginName+")";
this.getField("Date").value=util.printd("mm/dd/yy", new Date());
this.getField("Certificat").value=event.source.source.documentFileName.replace(".pdf","");
}
It's confusing to use parentheses in a field name, although it works. If you don't create a separate field for the script, change this.getField("FieldName").value to event.value for the field above containing the script.
Copy link to clipboard
Copied
Thank you for all the information.
I would indeed like to have a separate code for each field because the layout of my stamp is in the form of a table.
To summarize, on a user session with Adobe Pro:
I fill in the identity section in the preferences.
I create a stamp, retrieve my PDF file with the table layout and logo, choose the "Dynamic" category, and name the stamp.
I open my stamp located in C:\Users\[username]\AppData\Roaming\Adobe\Acrobat\DC\Stamps, which is named with several letters and numbers.
I create my three text fields and format them, then paste the custom script:
In the first field, Name (Identity):
In the second field:
In the third field:
I save, restart, and test on a document. If it works, I copy this file and place it in the AppData directory of another user.
I had a few questions:
Do I need to enable the JavaScript debugger to see errors?
What is the difference with this code from Tariq?
For dateField:
For fileNameField:
I assume that https://adobe.ly/3GtLxe3 is a display issue and that it should be identity.name, correct?
How do I use the method app.getIdentityString()?
If necessary, I prefer to clarify everything beforehand, as I do not have access to an Adobe Pro session as I would like.
Thank you in advance.
Copy link to clipboard
Copied
You can still put the entire code in one field, but that's your choice. Regarding step 4:
If you are going to put the scripts in each field, all instances of this.getField("FieldName") should be changed to event.value.
1. You need to open it (press Ctrl +j).
https://pdfautomationstation.substack.com/p/the-javascript-console
2. That code tests the identity.loginName property to see if it exists and if not, changes it to "NoID". I'm really sure how it could not exist. It also test the identity.name property for an error. If the name property is not filled in in the preferences, it will not throw an error, it will simply return nothing. @Tariq Ahmad 's file name script is pulling the stamp document file name, not the the doc being stamped, but he probably misunderstood that part of your question.
3. Correct.
4. I have no idea where that came from. There is no application method by that name that I can find.
This dynamic stamp video shows how to make one from scratch (without using the interface). It is helpful in learning all of the parts of the stamp.
Copy link to clipboard
Copied
Hello, I tried to follow the procedure to install the Adobe stamp on a user's session. I created a dynamic stamp from my PDF template, then I reopened my stamp from AppData and created the three necessary text fields (Name, Date, Certificate). I created a fourth field called "Script" to insert all the code at once:
After saving, I search for my file in AppData and overwrite it. I close Adobe, then reopen another PDF file to test, and my stamp appears but nothing is filled in. Attached is the stamp from AppData.
I don't understand how to do it? Best regards
Copy link to clipboard
Copied
You are referencing the wrong template name (AP) in your script. Change #RYR1Emk23H4sHB2rDWL_zB to #FyKxg3RHkTARzoly-AusJA and delete page 3 of your stamp file.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You're still getting the AP wrong in your script. This is it for the file you uploaded this time:
#eDfOEniZ99McqbVPx6QPDB
Copy link to clipboard
Copied
bonjour,
C'est beaucoup plus simple que ça, tu as juste besoin de ce script :
event.value=identity.name+" ("+identity.loginName+")";
this.getField("Date").value=util.printd("mm/dd/yy", new Date());
this.getField("Certificat").value=event.source.source.documentFileName.replace(/\.pdf$/i,"");
Ce qui donne avec le fichier joint :
@+
Copy link to clipboard
Copied
As mentioned previously in the thread, the conditional statements were included to avoid errors when the calculation runs before the stamp is applied and in case the file contained more than 1 stamp.
Copy link to clipboard
Copied
Hello, I tested the stamp by modifying the script with #eDfOEniZ99McqbVPx6QPDB and it works! Thank you very much! The script from "bebarth" also works, but it is indeed less secure if I use multiple stamps, which will be my case. I had a few other questions:
Thank you!
Copy link to clipboard
Copied
1. There are two ways to do this.
a) Open the stamp file and run the following script in the console: this.templates
b) Apply the stamp to a PDF, select the stamp and run the following script in the console: this.selectedAnnots[0].AP
https://youtu.be/DePWr_1lnYg?t=184
2) Yes. this.getField("File Name").value = app.repsonse("Enter file name:");
3) Make the stamp field a multiline text field.
4) By "lock", if you mean the locked check box in the appearance tab of the stamp properties is checked, you simply set the lock property of the stamp to true. Anybody can access the properties and uncheck the box. If you want the stamp to be locked so that there can be no user interaction with the stamp after it is placed, simply set the readOnly property to true. This can only be undone with a script. Having either of the settings executed automatically as the stamp is applied is proprietary information that I'm not willing to share here since most of the experts say it can't be done.
5. You'll have to either change the template name or the document Title (which is the category in the stamp menu). The template name mush begin with # or the stamp may only function once in a session.
Copy link to clipboard
Copied
Thank you so much!! I was able to create the second dynamic stamp with a pop-up and line break, also setting the font size to automatic. Note: it's "app.response" and you should use "," instead of "⨠". The read-only and locked properties don't affect the stamp itself, only within the script. However, if you right-click the stamp and choose Lock, then it can't be deleted.
Do you know if there's a way to make the stamp undeletable without having to perform this extra step?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now