Copy link to clipboard
Copied
Hi Community,
Is there a Java code I can use in Adobe Acobat where it automatically puts the date and time. I am not connected to a server. The document is not a form. Nor do I want to use a form field.
I am tested some code in the Java debugger it works, but it does not work when I go to Tools use JavaScript, then document java strings and create and use the script there.
Then when I add the code to a document action it still does not work on the document.
My question is what java code can I used to create a date and timestamp and I want it to appear on every page of the document. For example, if I have a ten page document I want the date for sure and a timestamp to be on all ten pages of the document. Where will I code this at in Adobe Acrobat so it can be on every page of the document.
I do not have a digital certificate.
Can I perform a date and time stamp without having to use a certificate, creating a form, or using a timestamp server. Can it be done with Java Code? Do you know what code to use and where would I put the code in Adobe Acobate? Thanks.
Copy link to clipboard
Copied
You can use this script to place a timestamp at the bottom of every page as a comment, which will be locked from editing.
You can change time format, text properties as you wish:
var currentDate = new Date();
var timestamp = currentDate.toLocaleString();
for (var i = 0; i < this.numPages; i++) {
var annot = this.addAnnot({
page: i,
type: "FreeText",
textFont: font.Helv,
textSize: 10,
contents: timestamp,
rect: [225, 13, 375, 49],
width: 1,
alignment: 1,
strokeColor: color.white,
lineWidth: 0,
lock: true
});
}
Copy link to clipboard
Copied
Yes, just add it to the 'contents' like this: contents: timestamp+" Thank you",
or if you wish to add it to a new line:
contents: timestamp+"\nThank you", in that case increase last rect from 49 to 60.
Copy link to clipboard
Copied
If you don't want to update every time when the document is opened, run the script once from console or put the script in a button and place a timestamp by clicking a button.
To use like this: Monday -December 04, 2023, Thank you
and to add it both at the top and at the bottom, use like this:
var currentDate = new Date();
var timestamp = util.printd("dddd -mmmm dd, yyyy", currentDate);
for (var i = 0; i < this.numPages; i++) {
// Add timestamp at the top of the page
var annotBottom = this.addAnnot({
page: i,
type: "FreeText",
textFont: font.Helv,
textSize: 10,
contents: timestamp + ", Thank you",
rect: [200, 760, 425, 780],
width: 1,
alignment: 1,
strokeColor: color.white,
lineWidth: 0,
lock: true
});
// Add timestamp at the bottom of the page
var annotTop = this.addAnnot({
page: i,
type: "FreeText",
textFont: font.Helv,
textSize: 10,
contents: timestamp + ", Thank you",
rect: [200, 15, 425, 35],
width: 1,
alignment: 1,
strokeColor: color.white,
lineWidth: 0,
lock: true
});
}
Copy link to clipboard
Copied
console.log doesn't work in Acrobat, change it to console.println
Copy link to clipboard
Copied
To make the button unusable (Read only) add this line after the script you already have in it:
event.target.readonly = true;
This will make the button read only, so you can't click on it.
Copy link to clipboard
Copied
The code Nesa provided will do that. Add it to the button's Mouse Up event.
Copy link to clipboard
Copied
Hi Community, I have another question. here is my code below. I am trying to get the previous codes to work with some code I saw online or in a book. the orginal code from the book or online is below.
{ var r = [200, 200, 400, 300]; var i = this.pageNum;
var f = this.addField(String("completeDate."+i),"text",i,r); f.textSize = 10; f.alignment = "right"; f.textColor = color.blue; f.fillColor = color.transparent; f.textfont = font.HelvB; f.strokeColor = color.transparent; f.value = String("This page was reviewed on: " + util.printd("mmm dd, yyyy", new Date())); f.readonly = true; }
I was able to get the correct answer. Thank you Adobe community.
Copy link to clipboard
Copied
Hi Nurani, Please ignore my last question. I may have figured part of it out.
Copy link to clipboard
Copied
Hi Nurani,
It is me again, the code below I found on another website and it is for Java script, however it does not work in the adobde acrobate java script. when the code is run on the website it works. The answer will be ideal for what I am looking for I may just have to forget about the time stamp. The code is below, let me know what you think and why it is not working in adobe java script. Can it be added to the code you gave me? or do I need to remove the console part?
This is the example that should appear at the bottom or top of the page:
December 18, 2023, 11:00 p. m. central time, Thank you 352.
or THANK YOU 352.
Thanks
var now = new Date(); var start = new Date(now.getFullYear(), 0, 0); var diff = (now - start) + ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000); var oneDay = 1000 * 60 * 60 * 24; var day = Math.floor(diff / oneDay); console.log('Day of year: ' + day);
Copy link to clipboard
Copied
The code is ideal because it updates the day of the year automatically..
Let me know if you want the website I saw it on. Thanks.
Copy link to clipboard
Copied
console.log doesn't work in Acrobat, change it to console.println
Copy link to clipboard
Copied
First thanks for all your assistance.
Do you know if you can create or have a timestamp by a timestamp sever without the signature. For Ex. date time , etc. (some other stuff). Or does Adobe timestamp server only provides timestamps for signature verification? Thanks.
Copy link to clipboard
Copied
Hi Community, I have another question. here is my code below. I am trying to get the previous codes to work with some code I saw online or in a book. the orginal code from the book or online is below.
{ var r = [200, 200, 400, 300]; var i = this.pageNum;
var f = this.addField(String("completeDate."+i),"text",i,r); f.textSize = 10; f.alignment = "right"; f.textColor = color.blue; f.fillColor = color.transparent; f.textfont = font.HelvB; f.strokeColor = color.transparent; f.value = String("This page was reviewed on: " + util.printd("mmm dd, yyyy", new Date())); f.readonly = true; }
I was able to get the correct answer. Thank you Adobe community.
Copy link to clipboard
Copied
Hi Nurani,
I have another question, sorry for the many questions.
The last code you gave me works, however I put the code to a button in adobe forms. Is there a way to gray out the button(make it unusuable once it is clicked with the last code you provided to me.
I tried this code from another website I like how the button greys out and becomes unusable after it is clicked on.
document.querySelector('button').addEventListener('click', function(){ this.disabled = true; })
<button>Button</button>
I like how the button greys out or becomes unusuable once it is clicked on. Is there a way to incorporate it with the last code you provided to me. I saw it on a Java website or Java Script website. It seems to not be working on the button I created with the forms feature in Adobe forms , run Java Script.
DDo I need to include the button name in the code. Or is there code to create and name the button and make it grey out after one time use? Thanks.
Copy link to clipboard
Copied
To make the button unusable (Read only) add this line after the script you already have in it:
event.target.readonly = true;
This will make the button read only, so you can't click on it.
Copy link to clipboard
Copied
Hi Nurani,
Not to make it so you can't click on it. Because I can make it a read only from the button properties menu.
After the button is clicked on, make it a read only or it because greyed out after one click.
Thanks.
Copy link to clipboard
Copied
Thanks for your help Nurani, I really appreciate it.
The Button needs to be clicked on only once then it should become a read only.
Copy link to clipboard
Copied
The code Nesa provided will do that. Add it to the button's Mouse Up event.
Copy link to clipboard
Copied
Ok, thanks.
Copy link to clipboard
Copied
Thank you for all of your help. Thanks for asking my many questions. I think Adobe should hire you to help on the blogs. I noticed that you have helped a lot of people for a while. Again, thanks for taking the time to answer my questions. 🙂 HAPPY HOLIDAYS!


-
- 1
- 2