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.
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,
strok
...
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.
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 = thi
...
console.log doesn't work in Acrobat, change it to console.println
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.
The code Nesa provided will do that. Add it to the button's Mouse Up event.
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
...Copy link to clipboard
Copied
Info: Acrobat uses JavaScript, not Java.
Copy link to clipboard
Copied
I meant JavaScript. Thanks. 🙂
Copy link to clipboard
Copied
Question, can I use any other scripting language in Adobe Acobat? Thanks.
Copy link to clipboard
Copied
You can add it as a watermark (using the addWatermarkFromText from text command), but if you want to update it later on it will overlap with the previous text you added. That's why using a field is better, as it's easier to update it.
Any specific reason you don't want to use a form field for this?
Copy link to clipboard
Copied
Yes, I thought about the watermark, but want the date or time stamp to be at the top or bottom of the document and do not want it to be edible by other users. I may have to reconsider using a field. Thanks.
Copy link to clipboard
Copied
The question is when do you want it to update, if at all. Should it update each time the file opened? Saved? Printed? Something else?
Copy link to clipboard
Copied
I want it to update when a task is completed or when the document is closed. However not every time it closes.
A form field may not be useful in this situation. Thanks for your comment.
Copy link to clipboard
Copied
May have to reconsider or change what I was trying to achieve. Thanks.
Copy link to clipboard
Copied
You have to clearly define when it should update, and when it shouldn't, or do it via a button so it updates when you click it.
Copy link to clipboard
Copied
Fortunately, you don't need JavaScript nor form fields to add a date to every page.
That's what the Header & Footer function is for, and it allows easy updates.
Copy link to clipboard
Copied
Yes, I thought about that but I don't want the date to be edible by other users. Yes, I know I can make it a read only, however the other users of the document may need to make notations on it. Thanks.
Copy link to clipboard
Copied
Other users must have Acrobat Pro to be able to edit Header & Footer.
You can restrict document modification without prohibiting comments.
Copy link to clipboard
Copied
Thank you, but did want to set a password. Sometimes the things we want to achieve may not be possible and this just may be one of those things. No password because there can possible be many users. Thanks for the suggestions.
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
Hi Nurani,
Thanks for the script I will try it over the weekend and let you know how it turns out. Happy Holidays.
Copy link to clipboard
Copied
Hi Nurani,
Wow! Thank you! It works! 🙂
Have a great weekend!
Copy link to clipboard
Copied
Hi Nurani,
The code works perfectly, however If I wanted to add the words "Thank you" to the comment will that be possible.
EX. Friday, Novermber 24, 2023
19:34:15, Thank You
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
ok, I will try it and let you know how it works. Thank you, again. You are the best! 🙂
Copy link to clipboard
Copied
It works! Awesome, I cannot thank you enough!
Copy link to clipboard
Copied
Hi Nurani,
I need your help again, please. When I play around with the rect it seems that the date updates everytime I open the document. Example, if I stampe it on today it says 12 04 2023, however when I open the doucment tomorrow it will say the 12 05 2023. I only want the date that is is stamp and not for it to update everytime I open the document.
Also, at the bottom of the page Can I have one 1 EX. Monday -December 04, 2023, Thank you.
Also, what if I wanted it one line at the top of the page?
Thanks.
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
Thank you again, Nurani, I will try it and see if it works.
May I ask do you work for Adobe? Or are you just a part of this community?
Copy link to clipboard
Copied
Hi Nurani and Community,
Nurani if you don't answer I understand, cause this is like my tenth time remodifying this question. OK,
So if I wanted a button to appear at the bottom or top of the page, Button named Finished. Once cliked on the button displays the current date and time if possible with the words Thanks you with the day of the year.
For Example, Today is November 16, 2023, 5:00 p.m. THANK YOU 320.
And the next day if someone clicks on the finish button it says November 17 2023 THANK YOU 321.
Is it possible? Is there a need for an array? I guess, I don't know for sure.
The button should appear at the top of the page a small button maybe within the very top of the page.
If the adding the days is not possible, what about just the button with the date and time and Thank you and should not update once the button has been clicked on. Once clicked on can the button be non functional non functional? Because the comments great, but the button will make it easier for other users to just click the botton.
THANKS FOR ALL YOUR HELP, IF YOU OR NO ONE ANSWERS I UNDERSTAND. I have modified this a lot.