13 Replies Latest reply on Jun 24, 2008 8:05 AM by (BChase)

    Menu Item to run trusted JavaScript problem

      I am trying to add a menu item that runs a script. I converted the script from a batch process and found that I have to make the addWatermarkFromFile a trusted function. I am having problems though. It errors with an internal error has occured. This is what I have:

      app.addSubMenu({ cName: "Specials", cParent:"Tools"});
      app.addMenuItem({ cName: "Convert to CCR", cParent:"Specials", cExec:" ConvertToCCR()"});

      function ConvertToCCR() {var size = this.getPageBox("Media"); if ((size[0] == 0) & (size[1] == 396) & (size[2] == 612) & (size[3] == 0))
      { this.setPageBoxes({cBox: "Media",rBox: [-90,-108,702,504]}); this.setPageBoxes({cBox: "Crop",rBox: [-90,-108,702,504]});
      trustedAddWatermark ({bOnTop:false, cDIPath:"/Macintosh HD/Users/ben/Desktop/Acrobat Reference PDF's/Copy Change Request Half.pdf"});

      var inch = 72;
      for (var p = 0; p < this.numPages; p++) {
      // position rectangle
      var aRect = this.getPageBox( {nPage: p} );
      aRect[0] += 7.08*inch; // from upper left hand corner of page.
      aRect[2] = aRect[0]+1.18*inch; // Make it 1.38 inch wide
      aRect[1] = 1.05*inch;
      aRect[3] = aRect[1] - 24; // and 25 points high
      // now construct text field
      var f = this.addField("Month 1", "text", p, aRect )
      f.borderStyle = border.s;
      f.alignment = "center";
      f.textSize = 14;
      f.textColor = color.black;

      var cRect = this.getPageBox( {nPage: p} );
      cRect[0] += 7.08*inch; // from upper left hand corner of page.
      cRect[2] = cRect[0]+1.18*inch; // Make it 1.38 inch wide
      cRect[1] = .72*inch;
      cRect[3] = aRect[1] - 46; // and 45 points high
      // now construct text field
      var f = this.addField("Month 1 Exp", "text", p, cRect )
      f.borderStyle = border.s;
      f.alignment = "center";
      f.textSize = 14;
      f.textColor = color.black;

      var f = this.getField("Month 1"); // get the Field Object
      var myRect = f.rect; // and get its rectangle
      // make needed coordinate adjustments for new field
      myRect[0] = f.rect[2]+.32*inch; // the ulx for new = lrx for old
      myRect[2] = myRect[0]+1.18*inch; // move two inches for lry
      f = this.addField("Month 2", "text", p, myRect);
      f.borderStyle = border.s;
      f.alignment = "center";
      f.textSize = 14;
      f.textColor = color.black;

      var f = this.getField("Month 1 Exp"); // get the Field Object
      var myRect = f.rect; // and get its rectangle
      // make needed coordinate adjustments for new field
      myRect[0] = f.rect[2]+.32*inch; // the ulx for new = lrx for old
      myRect[2] = myRect[0]+1.18*inch; // move two inches for lry
      f = this.addField("Month 2 Exp", "text", p, myRect);
      f.borderStyle = border.s;
      f.alignment = "center";
      f.textSize = 14;
      f.textColor = color.black;

      var bRect = this.getPageBox( {nPage: p} );
      bRect[0] += 6.08*inch; // from upper left hand corner of page.
      bRect[2] = bRect[0]+.69*inch; // Make it .68 inch wide
      bRect[1] = .72*inch;
      bRect[3] = cRect[1] - 22; // and 22 points high
      // now construct text field
      var f = this.addField("Rep", "text", p, bRect )
      f.borderStyle = border.s;
      f.alignment = "center";
      f.textSize = 14;
      f.textColor = color.black;}

      };};

      Then I also have another file called "trustedAddWatermark"

      trustedAddWatermark = app.trustedFunction( function (bOnTop, cDIPath) {
      app.beginPriv();
      this.addWatermarkFromFile ({bOnTop: false, cDIPath: "/Macintosh HD/Users/ben/Desktop/Acrobat Reference PDF's/Copy Change Request Half.pdf"});
      app.endPriv();
      } );

      Then I get the error in the JS console when it is run:

      TypeError: this.addWatermarkFromFile is not a function
      3:Folder-Level:User:trustedAddWatermark.js

      The thing that I don't get is if I put the 1st script in a button using the Form tools it works fine but I can't get it to work as a menu item. Where am I going wrong???