19 Replies Latest reply on Mar 24, 2017 5:10 AM by andrejtmtld

    Error when linking text to an PDF attachment - GeneralError: Operation failed. Root.(null):xxxx:Batch undefined:Exec script terminated

    andrejtmtld

      I created a JavaScript code which imports files into the attachment of a pdf form, then searches for the written pdf filenames within the pdf form and links the texts to the imported files. I employ Adobe Acrobat X (10.1.16)

       

      The code (which is run as folder-level JS)  is shown here:

      var impDatObj = app.trustedFunction( function(odoc,filenme,filepth) {
      app.beginPriv(); 
      odoc.importDataObject(filenme,filepth); 
      app.endPriv(); 
      });
      
      var attachpath="/mysrv/subdir/";
      
      impDatObj(this, "abcdef_g.pdf", attachpath+"abcdef_g.pdf"); 
      impDatObj(this, "987654_3.pdf", attachpath+"987654_3.pdf");
      
      var numPgs = this.numPages; 
      for (var jj=0; jj<numPgs; jj++) { 
          var numWords = this.getPageNumWords(jj); 
          for (var i=0; i<numWords; i++) {
              var ckWord = this.getPageNthWord(jj, i, false); 
              if (ckWord.indexOf("pdf")>=0) {
                  ckWord = ckWord.substring(0,  3); 
                  mm=i; 
                  var spc=true; 
                  do {
                     mm=mm-1; 
                     ckWord=this.getPageNthWord(jj, mm, false)+ckWord; 
                     if (mm>0) spc=(this.getPageNthWord(jj, mm-1, false).indexOf(" ")==-1); else if (mm==0) spc=true; else spc=false; 
                  } while (spc); 
              } 
              if (ckWord=="abcdef_g.pdf") { 
                  var m = (new Matrix2D).fromRotated(this,jj); 
                  var mInv = m.invert(); 
                  var q = this.getPageNthWordQuads(jj, i); 
                  var r = mInv.transform(q); 
                  r = r.toString(); 
                  r = r.split(","); 
                  var p = this.getPageNthWordQuads(jj, mm); 
                  var s = mInv.transform(p); 
                  s = s.toString(); 
                  s = s.split(","); 
                  var l = addLink(jj, [s[4], r[5], r[2], s[3]]); 
                  l.setAction("exportDataObject({cName: \"abcdef_g.pdf\", nLaunch: 2});"); 
              }
          }
      }
      
      var numPgs = this.numPages; 
      for (var jj=0; jj<numPgs; jj++) {
          var numWords = this.getPageNumWords(jj); 
          for (var i=0; i<numWords; i++) {
              var ckWord = this.getPageNthWord(jj, i, false); 
              if (ckWord.indexOf("pdf")>=0) {
                  ckWord = ckWord.substring(0,  3); 
                  mm=i; 
                  var spc=true; 
                  do {
                     mm=mm-1; 
                     ckWord=this.getPageNthWord(jj, mm, false)+ckWord; 
                     if (mm>0) spc=(this.getPageNthWord(jj, mm-1, false).indexOf(" ")==-1); else if (mm==0) spc=true; else spc=false; 
                  } while (spc); 
              }
              if (ckWord=="987654_3.pdf") {
                  var m = (new Matrix2D).fromRotated(this,jj); 
                  var mInv = m.invert(); 
                  var q = this.getPageNthWordQuads(jj, i); 
                  var r = mInv.transform(q); 
                  r = r.toString(); 
                  r = r.split(","); 
                  var p = this.getPageNthWordQuads(jj, mm); 
                  var s = mInv.transform(p); 
                  s = s.toString(); 
                  s = s.split(","); 
                  var l = addLink(jj, [s[4], r[5], r[2], s[3]]); 
                  l.setAction("exportDataObject({cName: \"987654_3.pdf\", nLaunch: 2});"); 
              }
          }
      }
      

      An error arises at the command:   l.setAction("exportDataObject({cName: \"987654_3.pdf\", nLaunch: 2});");

      Both documents are correclty uploaded into the attachment of the pdf form, the first text position is correctly linked.

       

      Who can help?