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

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

New Here ,
Sep 30, 2019 Sep 30, 2019

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

5.8K
Translate
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 ,
Sep 30, 2019 Sep 30, 2019

Where does you place the code?

Translate
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
New Here ,
Sep 30, 2019 Sep 30, 2019
In the action under page setting
Translate
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 ,
Sep 30, 2019 Sep 30, 2019
At all pages?
Translate
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
New Here ,
Sep 30, 2019 Sep 30, 2019
Yes only have one page
Translate
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
New Here ,
Sep 30, 2019 Sep 30, 2019
willing to pay you to fix
Translate
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
LEGEND ,
Sep 30, 2019 Sep 30, 2019

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

Translate
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
New Here ,
Sep 30, 2019 Sep 30, 2019
adobe reader
Translate
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 ,
Sep 30, 2019 Sep 30, 2019
Can you share the file?
Translate
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
New Here ,
Sep 30, 2019 Sep 30, 2019
okay I will upload when i get home from work
Translate
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
LEGEND ,
Sep 30, 2019 Sep 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.

 

Translate
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
New Here ,
Sep 30, 2019 Sep 30, 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!

Translate
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 ,
Sep 30, 2019 Sep 30, 2019
You can remove : and /
Translate
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
New Here ,
Oct 01, 2019 Oct 01, 2019
When I do hMMssmddyy without : / it has an error
Translate
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
LEGEND ,
Oct 01, 2019 Oct 01, 2019
It is within the quoted string in the "util.printd()" method.
Translate
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
New Here ,
Oct 01, 2019 Oct 01, 2019
var f = this.getField("Today"); f.value = util.printd("hMMssmddyy", new Date()); and date format set to custom hMMssmddyy
Translate
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 ,
Oct 01, 2019 Oct 01, 2019
What error?
Translate
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
New Here ,
Oct 01, 2019 Oct 01, 2019
adobe reader...... Invalid date/time: please ensure that the date/time exists. Field [ Today ] should match format hMMssmddyy" both are already matching
Translate
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
New Here ,
Oct 01, 2019 Oct 01, 2019
one last question for you... how do i trigger a botton to run the textfield code?...
Translate
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
LEGEND ,
Oct 02, 2019 Oct 02, 2019
I would remove the any entry on the "Format" tab. The script is providing the format.
Translate
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
New Here ,
Oct 02, 2019 Oct 02, 2019
Perfect
Translate
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 ,
Oct 02, 2019 Oct 02, 2019

Use something like this:

Sample

Translate
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
New Here ,
Oct 02, 2019 Oct 02, 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());.
Translate
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
New Here ,
Oct 08, 2019 Oct 08, 2019
Yes this is exactly right except when saved it needs to stay on the page as it is. how can i do that?
Translate
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
New Here ,
Oct 08, 2019 Oct 08, 2019
LATEST
Exactly correct! but when I save the page it needs to keep what was generated by clicking and not able to change again.
Translate
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