Skip to main content
April 30, 2014
Question

Auto Fill Today's date into a PDF form

  • April 30, 2014
  • 3 replies
  • 74749 views

What is the easiest way to autofill in Today's Date in a text box each time a pdf form is opened?

I found some answers on the forum but the version of acrobat was different from mine and the menu options were not the same.  I am using Adobe standard 9.

Thanks,

Vanessa

This topic has been closed for replies.

3 replies

June 16, 2014

Hi Gilad

I found your script above very useful to autopopulate a field with todays date.

this.addScript("init", "this.getField(\"Today\").value = new Date();");

I wonder if it is possible to lock it after the form has been opened so it doesn't update or change automatically. For example if I have a field with todays date in it using the script above. If I open the form tomorrow the same field would have tomorrow's date. Is there a way of keeping the field to todays date even though the form may be opened again in the future?

Regards,

Michael

Inspiring
August 22, 2014

You need to add some additional code to only fill-in the value of the field if it is equal to a null string or is empty.

function Initialize(cDateField) {

if(bInitialized == false || typeof bInitialized == "undefined") {

try{

// process only and empty field;

if(this.getField(cDateField).value == "") {

this.getField(cDateField).value = new Date();

bInitialized = true;

} // end empty field;

}catch(e) {

bInitialized = false;

} finally {

return bInitialized;

} // end try;

} // end bInitialized false or undefined;

} // end Initialize function;

if(typeof bInitialized == "undefined") var bInitialized = false;

Initialize("MyDateField");

Now you will need to figure out how to distribute the form so the date field will fill-in when the form is empty.

Inspiring
April 30, 2014

If one has the Standard version of Acrobat, you can use the "Open Page" action. And the code could be add to all pages. I would create an initialization function and docuement variable to see if the initialization function has been run.

function Initialize(cDateField) {

if(bInitialized == false || typeof bInitialized == "undefined") {

try{

this.getField(cDateField).value = new Date();

bInitialized = true;

}catch(e) {

bInitialized = false;

} finally {

return bInitialized;

} // end try;

} // end bInitialized false or undefined;

} // end Initialize function;

if(typeof bInitialized == "undefined") var bInitialized = false;

Initialize("MyDateField");

try67
Community Expert
Community Expert
April 30, 2014

You don't have direct access to the doc-level scripts in your version of Acrobat, but you can set do it via the console.
Run this code:

this.addScript("init", "this.getField(\"Today\").value = new Date();");

Of course, you should have a text field in your file called "Today", set up as a Date field.

April 30, 2014

Can you tell me how to get to the console? I tried following the instructions in the knowledge base but when I go to set preferences, again, my screen doesn't look like the example shown. I'm obviously a novice.

Vanessa Lo, PA-C

Premier Orthopaedics & Sports Medicine

Centennial Medical Center

2400 Patterson Street Suite 300

Nashville, Tennessee 37203

615-342-6368