Windows Explored

Everyday Windows Desktop Support, Advanced Troubleshooting & Other OS Tidbits

User Request – Automatically Insert Current Date Into PDF

Posted by William Diaz on August 20, 2010


What the user wants, the user gets. Especially when they tell you someone else has it or someone smarter than you did this for them a long time ago. The request here was to automatically populate several date fields in a PDF with the current date and time the PDF was opened. The idea was to expedite the filling out of the form so that it could quickly be printed out and sent out for hand delivery. 

Most PDF editing apps can accomplish with a little Java script. In the example here, I am using the PDF Converter Professional application but the steps below are similar for Adobe Acrobat or any other PDF editor. The task is to link the Java script to the various text date fields. By default, the text fields are named Text1, Text2, etc. or they can be renamed.

Once you know the field name, go to Document > JavaScript > Document JavaScripts > Add.

Create a document JavaScript name, click OK, then select Edit and paste the following:

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

Note, “Date” is the name of the text field you are linking it to. You can also change the format of the date or add additional Java code within the quotes to, e.g. add the time as well (“HH:MM”). When completed, click Close. The current date will automatically be inserted each time the PDF is open. It doesn’t matter which PDF viewer it is opened with, the date will always be updated. Because of this, ideally the PDF is not intended to shared in this format since the date/time will continue to change each time it is opened. To avoid this, you can remove the Java script by printing the PDF to PDF, e.g. BullZip PDF, which would then ideally make it suitable for sharing as a file.

Alternatively, you can also link the text field and JavaScript to an action if the effect is to only update with the current date when the field is clicked. To do this, skip the step where you created and linked the JavaScript using the Document menu. Instead, right click-click the text field and select Properties and go to the Actions tab. From the Select Trigger menu change to On Focus and under Select Action choose Run a JavaScript. When done, select the action and then Edit and copy the script above.

Now the date will be updated whenever the text field is selected.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: