I am trying to add a FreeText annotation to a PDF programmatically using JavaScript. When I try to call a function specifying the FreeText annotation directly from the menuItem, everything works as expected. When I try to call the FreeText annotation from another function, I get an error "TypeError: this.addAnnot is not a function". I am not sure what is wrong. I have included my code below. Your help is much appreciated.
Code:
app.addSubMenu({cName: "Tech Services", cParent: "Edit"});
app.addMenuItem({cName: "Add SO Info", cParent: "Tech Services", cExec: "addSalesOrderInfo();"});
function addSalesOrderInfo() {
addSerialNumber();
//addSalesOrderNumber();
//addEhProjectNumber();
//addNosetype();
//addNumberOfUnits();
}
// add serial number textbox
function addSerialNumber() {
// get serial number(s)
var snValue = app.response({
cQuestion: "Enter Serial Number(s)",
cTitle: "SERIAL NUMBER ENTRY",
cDefault: "N/A",
cLabel: "Serial Number(s):"
});
// create text box
var sn = this.addAnnot({
page: 0,
type: "FreeText",
rect: [672,355,672+7,355+75],
name: "SerialNo",
author: "Admin",
});
// set properties of textbox
var spans = new Array();
spans[0] = new Object();
spans[0].text = snValue;
spans[0].textColor = color.black;
spans[0].textFont = "Arial";
spans[0].textSize = 8;
spans[0].alignment = "center";
// assign properties to rich contents of textbox
sn.richContents = spans;
}