Copy link to clipboard
Copied
Question in the title. I think it is possible but apparently I'm too unable to do it
Copy link to clipboard
Copied
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]);
Copy link to clipboard
Copied
Please post the code you are using, and any error message from the console.
Copy link to clipboard
Copied
Fields can be created using the addField method of the Document object. How to use it is documented in the Acrobat JS API Reference.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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]);

Copy link to clipboard
Copied
Hello. I have had mixed success with locating the text box. When I first set up the scripting into an Action, I was able to get the proper placement. The next time I launched Acrobat and ran the Action, the horizontal (side to side) is fine, but the vertical is wrong, with the top of box appearing at 8.5 inches up from the bottom. If I slightly increase the uly value, the text starts vanishing (as if appearing off the top of the page). I'm marking thousands of mulitple page documents with a Printed On date, so this has to work reliably.
// from left edge of letter sized page, left side of box
var ulx = 85;
// up from bottom of page, top of box (top edge of page)
var uly = 792;
// from left edge of page, right side of box (box is now 203 pt width)
var lrx = 288;
// up from bottom of page, bottom of box (box is now 22 pt tall)
var lry = 772;
for (var p=0; p<this.numPages; p++)
{
var bf = this.addField("watermark", "text", p, [ulx,uly,lrx,lry]);
bf.borderStyle = border.s;
bf.lineWidth = 2;
bf.textColor = color.black;
bf.textFont = "Arial";
bf.textSize = 10;
bf.display = display.noview;
}
/* print Time and Date */
this.seAction("WillPrint", "var f = this.getField(\"watermark"\); f.value = util.printd(\"m/d/yyyy HH;MM\", new Date());");
Copy link to clipboard
Copied
The script needs to calculate the position in order to handle different page coordinates.
Here's an article on this topic:
https://www.pdfscripting.com/public/PDF-Page-Coordinates.cfm?sd=40
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
So it works like this.addField("Name", "type", pagenumber, [?,height,width,?])
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
How come doesn't it work with a button? If I use this.addField("Text1", "button", 0, [0,100,100,0]), nothing happens
Copy link to clipboard
Copied
Use a other name for the button.
Copy link to clipboard
Copied
var f = this.addField("Textbox1", "text", 0, [0,792,100,692]);
f.borderStyle = border.m;
f.value = "Hello world!";
f.textSize = 12;
f.textfont = font.Arial;
f.textColor = color.black;
Why doesn't this put "Hello world!" into my textfield?
Copy link to clipboard
Copied
You have several errors in your code. Check the JS Console when you run it...
Copy link to clipboard
Copied
You can't have two fields of different types and the same name, so either delete the text field with that name, or change the name of the button you're trying to add.

