Placing the current date in the text box of a PDF using JavaScript

I like to create a PDF file that when printed includes the date and time it was printed. Since a PDF editor would be required to actually modify the contents of the PDF, I thought using a PDF form (i.e. a PDF that contains a fillable form) where one text box is automatically updated with the current date and time the PDF was printed. Actually creating a pdf address is not the purpose of this question (the goal is to use pdflatex , which can put javascript in pdf files).

I know that PDF files may contain JavaScript code, but there are limitations compared to websites. Is it possible, for example, to support the Adobe Adobe JavaScript API, to have a script that:

  • runs when printing PDF
  • can change a text box or something else that prints in plain text
  • update this field with current date / time?
+4
source share
2 answers

After watching this post, I wrote an article for our product in PDF format - Creating print-only PDF content - to show that it is really possible, What I did was create a form field that is hidden on the screen but accessible when printing. Then I added a JavaScript PDF action for the "before printing" event of the document so that the form field value is set to the current date and time.

DISCLAIMER: I work for the Gnostis.

+2
source

Yes it is possible. PDF documents support the WillPrint action, which is executed before the document is printed. You set this action using a javascript action that retrieves the current date and time and sets the value of the field with that date.

The fact is that not all PDF readers support Acrobat JavaScript code, so the WillPrint action may not work.

+3
source

Source: https://habr.com/ru/post/1344823/


All Articles