• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

TypeError: this.addAnnot is not a function

New Here ,
Jul 05, 2021 Jul 05, 2021

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:

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;   
}
TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 05, 2021 Jul 05, 2021

The meaning of "this" changes so never use it in a function. Instead pass the target field as a parameter. 

Votes

Translate

Translate
LEGEND ,
Jul 05, 2021 Jul 05, 2021

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 05, 2021 Jul 05, 2021

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines