Skip to main content
Known Participant
March 16, 2018
Answered

How can I create a text field by using javascript?

  • March 16, 2018
  • 3 replies
  • 17606 views

Question in the title. I think it is possible but apparently I'm too unable to do it

This topic has been closed for replies.
Correct answer try67

This code will add a 100x100pt text field (called "Text1") at the lower left corner of the first page of the file:

this.addField("Text1", "text", 0, [0,100,100,0]);

3 replies

Known Participant
March 16, 2018

So it works like this.addField("Name", "type", pagenumber, [?,height,width,?])

try67
Adobe Expert
March 16, 2018

Not quite regarding the last parameter. From the API Reference:

oCoords : An array of four numbers in rotated user space that specifies the size and placement

of the form field. These four numbers are the coordinates of the bounding rectangle,

in the following order: upper-left x, upper-left y, lower-right x and lower-right y. See

also the Field object rect property.

Known Participant
March 16, 2018

How come doesn't it work with a button? If I use this.addField("Text1", "button", 0, [0,100,100,0]), nothing happens

try67
Adobe Expert
March 16, 2018

Fields can be created using the addField method of the Document object. How to use it is documented in the Acrobat JS API Reference.

Known Participant
March 16, 2018

Could you please give me a most easy example of addField with all the necessary parameters? In the API there's just some advanced example I don't really get. Sorry, pretty new on that.

try67
try67Correct answer
Adobe Expert
March 16, 2018

This code will add a 100x100pt text field (called "Text1") at the lower left corner of the first page of the file:

this.addField("Text1", "text", 0, [0,100,100,0]);

Brainiac
March 16, 2018

Please post the code you are using, and any error message from the console.