I like to create a PDF which when printed out includes the date and time of when it was printed. Because actually changing the PDF content would require a PDF editor I thought using a PDF form (i.e. a PDF which contains a fillable form) where ane text field is automatically updated with the current engagement and time when the PDF is printed. The actual cosmos of the PDF is not target of this question (the goal is to use pdflatex which can place JavaScript into PDFs).

I know that PDFs can include JavaScript code, but there are limitation compared to websites. Is it possible, i.due east. supported past the Adobe PDF JavaScript API, to have a script which:

  1. is triggered when the PDF is printed
  2. tin can modify a text field or something else which is printed with the normal text
  3. update this field with the current engagement/time?

user avatar

asked Mar 22, 2011 at xix:nineteen

user avatar

two Answers 2

Yes, it is possible. The PDF documents support a WillPrint action that is executed before the certificate is printed. You set this activeness with a javascript activeness that retrieves the electric current appointment and time and sets a field value with this date.

The affair is that not all PDF viewers back up Acrobat javascript code so the WillPrint activeness might not exist executed.

answered Mar 22, 2011 at nineteen:52

user avatar

Subsequently seeing this post, I wrote an commodity for our PDF product - Creating Print-But PDF Content - to show that this is indeed possible. What I have done is create a course field that is hidden on the screen but bachelor when printed. I and then added a JavaScript PDF action to the "before print" event of the document and then that the grade field value was ready to the current date and time.

DISCLAIMER: I work for Gnostice.

answered Mar 23, 2011 at 8:xvi

user avatar

2

  • Wow. Thanks! That shows me what is required to achieve it. I will convert that from Java to pdfTeX.

    Mar 23, 2011 at 8:38

  • I have added the apparently JavaScript in a Java comment so that information technology can be easily lifted. The PDF with print-only content is also available for download and testing.

    Mar 24, 2011 at iv:13

Not the answer yous're looking for? Scan other questions tagged javascript forms datetime pdf dom-events or ask your own question.