Ghostscript's pdfwrite device supports many of the PostScript pdfmark operations (but not all). No there's no documentation on which ones are supported, but broadly speaking everything except the logical structure ones.
The pdfmark reference (available from the Adobe web site, somewhere.....) describes the pdfmark syntax and in combination with the PDF Reference Manual (or the ISO specification) we can see that JavaScript is restricted to Widget Annotations. There's even en example in the pdfmark reference, so I did the obvious, and tried it. The following code does 'something'. I presume its correct but have no way of knowing for sure (that is, the PDF stuff is correct; I have no idea about JavaScript):
[
/Subtype /Widget
/Rect [216 647 361 684]
/F 4
/T (SL Text)
/FT /Tx
/DA (/Helv 14 Tf 0 0 1 rg)
/V (5)
/AA <<
/K <<
/S /JavaScript
/JS (AFNumber_Keystroke\(2, 0, 0, 0, "$", true\);)
>>
/F <<
/S /JavaScript
/JS (AFNumber_Format\(2, 0, 0, 0, "$", true\);)
>>
>> /ANN pdfmark
showpage
That draws a light blue rectangle, when you mouse over it draws a black border, when you click it, it displays the value 5. Replace the 5 with a numeric value and press return and it becomes $value.00 on a blue background. Kind of looks right.
Note that the example you linked to above won't help you, that's to do with pure PostScript. In order to add an annotation like this you will need to:
- Be using the Ghostscript pdfwrite device
- create a command line where you first process the existing PDF file
- On the command line after processing the existing PDF file, execute PostScript (using a pdfmark, as above but not the showpage, just the pdfmark section) to define the annotation. You will need to use the -c (introduce PostScript) and -f (end PostScript) switches to do this.