Skip to main content
Known Participant
September 30, 2019
Question

trying to add current date and time to my PDF and it is not working... need help

  • September 30, 2019
  • 4 replies
  • 6031 views

I am trying to do the following.


var f = this.getField("Today");
f.value = util.printd("mmm/d/yyyy", new Date());


It works in acrobat but when I save as PDF it becomes static and no longer works.

I've been trying for 1 week everyday for hours and can not get it to work.

 

What can I be doing wrong?

 

 

 

Thanks

    This topic has been closed for replies.

    4 replies

    Bernd Alheit
    Community Expert
    Community Expert
    October 2, 2019

    Use something like this:

    Sample

    Known Participant
    October 2, 2019
    Yes I got it to work copying yours but with my code it would not work correctly. The problem is when the doc is saved or sent in an email it will not save the time and date generated at that time of clicking the button. this code is working for what i needed but no button var f = this.getField("TimeStamp"); if (f.valueAsString=="") f.value = util.printd("mmddyyyyHHMM", new Date());.
    Inspiring
    September 30, 2019

    That article describes how someone with Acrobat Standard can add the script if they do not know how to add a document level script without the GUI in the Form Tool.

     

    Example Acrobat JavaScripts provides an extensive document level script in form that will only run once when the form is opened in Acrobat or Reader. There is also a link to an example file.The script issues a warning that the field is about to be updated. I have tried it in both Acrobat DC and Reader DC and the script runs.

     

    If one wants to see the update change the value of the field in less than 24 hours, one can change the date format to include the time showing the hours, minutes and seconds. Your script will only work when the page on which the script is located is opened. So if one opens the PDF on say page 2 and the field is on page one, the field will not be updated. Using the document level script will update the field regardless of the page on which the field is located.

     

    How have you determined that the field becomes static?

     

    I created a PDF with your script but did not make the field read only and cleared the field before saving. The script ran. 

     

    Another thing to do would be to open the JavaScript console and see if there are any errors.

     

    Known Participant
    October 1, 2019

    I got it to work! I re did the whole thing on another computer at home and it worked... now lets see if i take it back to my work computer if it will still be working then. Is there anyway I can remove the : from the time and the / from the date without setting off an error? Thanks for the help!

    Known Participant
    October 1, 2019
    What error?
    adobe reader...... Invalid date/time: please ensure that the date/time exists. Field [ Today ] should match format hMMssmddyy" both are already matching
    Legend
    September 30, 2019

    What is the app or browser in which it "becomes static"? 

    Known Participant
    September 30, 2019
    adobe reader
    Bernd Alheit
    Community Expert
    Community Expert
    September 30, 2019
    Can you share the file?
    Bernd Alheit
    Community Expert
    Community Expert
    September 30, 2019

    Where does you place the code?

    Known Participant
    September 30, 2019
    In the action under page setting
    Bernd Alheit
    Community Expert
    Community Expert
    September 30, 2019
    At all pages?