Javascript in PDF using LaTeX

Yesterday, I tried to measure the startup time of Adobe Reader (AR) on Windows and wondered if I could create a PDF file triggering the AR application exit on load of itself. For some hours, I wondered how the hell to include Javascript in a PDF document without having to use Acrobat.

I found a neat way to include Javascript in a PDF file: using LaTeX! Look at this piece of code:

app.alert("HALLO WELT");

I compiled this using PDFLaTeX, yielding the following result:

The insdljs package is providing the \OpenAction command, which lets you define Javascript code executed on loading the PDF document at page one. And much more is possible. Together with some other packages collected in the AcroTeX [1] package, you can create interactive PDF documents using LaTeX, as partly presented in [2]. An entire documentation for creating such documents is provided in [3]. The Javascript API you can use for the Adobe Reader is documented in [4]. Unfortunately, there is no way to close the parent application using Javascript, so this whole approach was not useful for my initial problem. Anyway, I’ve learned something.