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.
|var f = this.getField
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.
Now the date will be updated whenever the text field is selected.