14
  1. Can someone please show me an example of how to include a simple Javascript form within a pdflatex document?

  2. Can someone please show me an example of accessing and modifying the PDF file's DOM from Javascript within a pdflatex document?

  3. Is there some reasonably friendly document to describe how to intermix PDF and Javascript?

N.N.
  • 36,163
  • 2
    AFAIK, you cannot edit the DOM of the PDF file (as there is no DOM as in HTML). See "Where Can You Use JavaScript?" in the JavaScript Manual "Acrobat JavaScript Object Specification" – topskip Oct 06 '11 at 16:52
  • @Werner: No typo, it's a form, as in "fill out", not from, as in "indicating the source". – doncherry Oct 06 '11 at 16:58
  • 1
    @doncherry: M'kay. – Werner Oct 06 '11 at 17:05
  • I wrote some javascript stuff. It seems there are ways to create new form elements - but no matter if Adobe provides DOM or any object model at all: documents generated by TeX do not enable such modifications. At least that's what I understood when I tried to use the API methods to crerate objects. Apparently, a document needs to be encrypted in order to create new objects. It is ok to modify existing objects, though (like text fields or buttons). – Christian Feuersänger Dec 16 '11 at 14:49

2 Answers2

8

You might try the manual to the eforms package. eforms is another interface (other than hyperref) for creating PDF forms in TeX. The manual includes many simple examples.

There is no DOM in PDF. If you want parts of the PDF to change based on form events, you pretty much have to make those changing things read-only text fields.

For intermixing JavaScript and your TeX code see this demo of the insDLJS package

Both of the docs (and the packages they document) are written by D.P. Story, who is extremely prolific in this area. His acrotex bundle has many more examples.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
7

Try the following tex file:

\documentclass{article}
\usepackage[pdftex]{insdljs}
\OpenAction{\JS{%
app.alert("HALLO WELT");
}}     
\begin{document}
THIS DOCUMENT IS A DOCUMENT
\end{document}

For more information, look at the official document!

hsxz
  • 71