To process document events we have to add an /AA entry to the \textsc{pdf} catalogue. The entry value must be a dictionary defining event handlers. Entries in this dictionary are key/value pairs, the value is again a dictionary specifying the action to take.\\ The following keys can occur:\\[0.5em] \begin{tabular}{|r|l|} \hline &\\*[-0.9em]\multicolumn{1}{|c|}{\textbf{Key}}&\multicolumn{1}{c|}{\textbf{Event}}\\ \hline &\\*[-0.9em]/WP&The document will be printed.\\ \hline &\\*[-0.9em]/DP&The document was printed.\\ \hline &\\*[-0.9em]/WS&The document will be saved.\\ \hline &\\*[-0.9em]/DS&The document was saved.\\ \hline &\\*[-0.9em]/DC&The document will be closed.\\ \hline \end{tabular}\\[0.5em] In the example we run \textit{willPrint();\/} for the WillPrint event and \textit{didPrint();\/} for the DidPrint event. \begin{lstlisting} \immediate\pdfobj{ << /WP << /S /JavaScript /JS (willPrint();) >> /DP << /S /JavaScript /JS (didPrint();) >> >> } \pdfcatalog{/AA \the\pdflastobj\space 0 R} \end{lstlisting} Before and after printing ex0008.pdf a message box is shown. \lstinputlisting{../examples/ex0008.tex} In ex0009.pdf we change stroke and fill colors and text fonts before and after printing. We have to change the \textit{fillColor\/}, \textit{strokeColor\/} and \textit{textFont\/} attributes.\\ The changes are enclosed in \begin{lstlisting} this.delay = true // ... this.delay = false \end{lstlisting} to avoid multiple screen refreshes after each change. In \textit{myFirstJavaScriptFunction()\/} we set defaults for the choice lists \textit{abt\/} and \textit{zeit\/} using: \begin{lstlisting} this.getField("abt").currentValueIndices = 0; this.getField("zeit").currentValueIndices = 0; \end{lstlisting} We set the focus to the \textit{vorname\/} field by: \begin{lstlisting} this.getField("vorname").setFocus(); \end{lstlisting} \lstinputlisting{../examples/ex0009.tex}