Copy link to clipboard
Copied
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:
The meaning of "this" changes so never use it in a function. Instead pass the target field as a parameter.
Copy link to clipboard
Copied
The meaning of "this" changes so never use it in a function. Instead pass the target field as a parameter.
Copy link to clipboard
Copied
Thank you for the help. I changed the code to:
function addSalesOrderInfo() {
addSerialNumber(this);
//addSalesOrderNumber();
//addEhProjectNumber();
//addNosetype();
//addNumberOfUnits();
}
// add serial number textbox
function addSerialNumber(target) {
// 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 = target.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;
}
Everything is now working as expected.