4 Replies Latest reply on Sep 10, 2014 2:03 PM by gkaiseril

    Running a function from a addToolButton

    subieguy2 Level 1

      I have code that I run from the document level javascript window in Acrobat 8 Pro. I am wanting the code to run as if it were placed in the document javascripts window and executed when you click the tool button at the top.
      I am struggling to figure out what I am missing...any help would be greatly appreciated!

      Here is the code:

       

      app.addToolButton({

             cName: "highlightReport", // A name for your button

             cExec: "highlightReport();", //Function to Call

             cLabel: "Highlight Report", //The Text on the Button

             cTooltext: "Show me the report" //The Help Text

      });

       

       

      function highlightReport()

      {

       

       

      var buttPages = new Array();

      var generateReport = new Report();

      /* ---------- Callout report ---------- */

      var grids = new Array();

      initgrids();

      function initgrids(){

      for(var f=1; f<this.numFields;f++){

      if(this.getNthFieldName(f).indexOf(" mv") != -1){

      var newField = this.getField(this.getNthFieldName(f));

      if (typeof newField.page != "undefined"){

      if (typeof newField.page == "number"){

      buttPages.push(newField.page);

      }

      else{

      buttPages.push(newField.page[0]);

      }}

      grids.push(newField);

      generateReport.size = .5;

      generateReport.color = color.black;

      generateReport.writeText("// Function for CALLOUT " + newField.name.substring (0, 3));

      generateReport.writeText("function callout" + newField.name.substring (0, 3) + "(){");

      generateReport.writeText("this.gotoNamedDest('mv" + newField.name.substring (6, 8) + "');");

      generateReport.writeText('var Callout = "Callout ' + newField.name.substring (0, 3) + '";');

      generateReport.writeText('var PasteFirst = "Paste 1st (Data)";');

      generateReport.writeText("var ocgArray = this.getOCGs(this.pageNum);");

      generateReport.writeText("for ( var i=0; i < ocgArray.length; i++) {if ( ocgArray[i].name == Callout ) {ocgArray[i].state = true;}");

      generateReport.writeText("else ocgArray[i].state = false;}");

      generateReport.writeText("for ( var z=0; z < ocgArray.length; z++) {if ( ocgArray[z].name == PasteFirst ) {ocgArray[z].state = true;}}");

      generateReport.writeText("onlygrid(" + grids.length + ", " + newField.page + ");");

      generateReport.writeText("turnOffConns(0, " + newField.page + ");}");

      generateReport.writeText(" ");

      }}}

      /* ---------- CONN REPORT ---------- */

      var conns = new Array();

      initconns();

      function initconns(){

      for(var f=1; f<this.numFields;f++){

      if(this.getNthFieldName(f).indexOf(" cv") != -1){

      var newField = this.getField(this.getNthFieldName(f));

      if (typeof newField.page != "undefined"){

      if (typeof newField.page == "number"){

      buttPages.push(newField.page);

      }

      else{

      buttPages.push(newField.page[0]);

      }}

      conns.push(newField);

      generateReport.writeText("// Function for CONN " + newField.name.substring(0, 4) + " Volume " + newField.name.substring(7, 8));

      generateReport.writeText("function conn" + newField.name.substring(0, 4) + "v" + newField.name.substring(7, 8)+"(){");

      generateReport.writeText("this.gotoNamedDest('mv" + newField.name.substring(10, 12) + "');");

      generateReport.writeText('var CONN = "CONN ' + newField.name.substring (0, 4) + " v" + newField.name.substring(7, 8) + '";');

      generateReport.writeText('var PasteFirst = "Paste 1st (Data)";');

      generateReport.writeText("var ocgArray = this.getOCGs(this.pageNum);");

      generateReport.writeText("for ( var i=0; i < ocgArray.length; i++) {if ( ocgArray[i].name == CONN ) {ocgArray[i].state = true;}");

      generateReport.writeText("else ocgArray[i].state = false;}");

      generateReport.writeText("for ( var z=0; z < ocgArray.length; z++) {if ( ocgArray[z].name == PasteFirst ) {ocgArray[z].state = true;}}");

      generateReport.writeText("onlyconns(" + conns.length + ", " + newField.page + ");");

      generateReport.writeText("turnOffCallouts(0, " + newField.page + ");}");

      generateReport.writeText(" ");

      }}}

      generateReport.open("Callout and CONN Function");

      }

       

       

       

       

      Windows 7 64 bit and Acrobat 8 Pro