Skip to main content
Apr 30, 2014 1:29 PM UTC
Question

Auto Fill Today's date into a PDF form

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 is closed to new replies. Start a new post to keep the conversation going.

30 replies

Jun 16, 2014 2:57 AM UTC

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

Translate
Inspiring
Aug 22, 2014 8:15 PM UTC

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.

Translate
Inspiring
Apr 30, 2014 5:08 PM UTC

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

Translate
try67
Community Expert
Community Expert
Apr 30, 2014 1:40 PM UTC

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.

Translate
Apr 30, 2014 6:22 PM UTC

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

Translate