• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
3

timestamp Java Code

Explorer ,
Nov 20, 2023 Nov 20, 2023

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. 

 

 

TOPICS
How to

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 7 Correct answers

Community Expert , Nov 22, 2023 Nov 22, 2023

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
...

Votes

Translate

Translate
Community Expert , Nov 25, 2023 Nov 25, 2023

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.

Votes

Translate

Translate
Community Expert , Dec 04, 2023 Dec 04, 2023

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
...

Votes

Translate

Translate
Community Expert , Dec 18, 2023 Dec 18, 2023

console.log doesn't work in Acrobat, change it to console.println

Votes

Translate

Translate
Community Expert , Dec 26, 2023 Dec 26, 2023

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.

Votes

Translate

Translate
Community Expert , Dec 27, 2023 Dec 27, 2023

The code Nesa provided will do that. Add it to the button's Mouse Up event.

Votes

Translate

Translate
Explorer , Feb 04, 2024 Feb 04, 2024

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

...

Votes

Translate

Translate
Community Expert ,
Nov 20, 2023 Nov 20, 2023

Copy link to clipboard

Copied

Info: Acrobat uses JavaScript, not Java.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

I meant JavaScript. Thanks. 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

Question, can I use any other scripting language in Adobe Acobat? Thanks. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2023 Nov 21, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2023 Nov 21, 2023

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2023 Nov 21, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2023 Nov 21, 2023

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. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

May have to reconsider or change what I was trying to achieve.  Thanks. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2023 Nov 22, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2023 Nov 21, 2023

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.

 

Capture_2311211243.png

 

Capture_2311211250.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2023 Nov 21, 2023

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2023 Nov 21, 2023

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.

 

Capture_2311211259.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2023 Nov 21, 2023

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2023 Nov 22, 2023

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
    });
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2023 Nov 22, 2023

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

Hi Nurani,

 

Wow! Thank you! It works! 🙂

 

Have a great weekend!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2023 Nov 24, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2023 Nov 25, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 25, 2023 Nov 25, 2023

Copy link to clipboard

Copied

ok, I will try it and let you know how it works.  Thank you, again.  You are the best!  🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 25, 2023 Nov 25, 2023

Copy link to clipboard

Copied

It works! Awesome, I cannot thank you enough!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 04, 2023 Dec 04, 2023

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2023 Dec 04, 2023

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
    });
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 05, 2023 Dec 05, 2023

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 09, 2023 Dec 09, 2023

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. 

 

 

 

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines