Reputation: 333
I'm using Javascript within a PDF editor.
I'm using this reference https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf
I'm trying to set an action on a field when a mouseEnter event is triggered on that field. Below is my code.
var myDoc = app.newDoc(); // Create a blank doc
var Bbox = myDoc.getPageBox("Crop"); // Get crop box
var inch = 72;
// Add a text field at the top of the document
var f = myDoc.addField("Name.Last", "text", 0,[ inch, Bbox[1]-inch, 3*inch, Bbox[1]- inch - 14 ] );
f.setAction("MouseEnter", "f.textColor = color.yellow"); // Add an action
However i get the following error:
======== Field : mouse enter ========
[ Line: 00000 { ReferenceError } ] : f is not defined
I thought i had defined the field f using this line here:
var f = myDoc.addField("Name.Last", "text", 0,[ inch, Bbox[1]-inch, 3*inch, Bbox[1]- inch - 14 ] );
Why is the error saying my field is not defined?
Upvotes: 1
Views: 648
Reputation: 4927
Adobe Reader cannot modify the page content of PDF files. Doc.addField() and Field.setAction() both attempt to make changes to the PDF that Reader cannot make.
You get the error because the field did not get added so f is undefined.
You can't create new PDF files using Reader either.
This code would likely run successfully, though I haven't tested it, in Adobe Acrobat Pro.
Upvotes: 2