Skip to main content
Inspiring
March 17, 2017
Answered

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

  • March 17, 2017
  • 2 replies
  • 2419 views

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?

This topic has been closed for replies.
Correct answer andrejtmtlsm

Looks like a problem with setAction.


I checked the whole loop in the JS debugger... The issue is not related to setAction, but to the for-loop. I assume that searching for a text (which will be linked) can be implemented in a more clever way.

Thanks anyhow!

2 replies

Bernd Alheit
Community Expert
Community Expert
March 20, 2017

You use the whole code in a folder-level JavaScript file?

Inspiring
March 20, 2017

Yes, exactly. Actually I created a Sequence File (SEQU) with this content and further commands to add checkboxes to a stactic PDF file to make it a PDF form with attachments.

Bernd Alheit
Community Expert
Community Expert
March 20, 2017

A folder-level JavaScript file and a sequence file is not the same.

Code in folder-level JavaScript files will be executed at startup of Adobe Acrobat.

try67
Community Expert
Community Expert
March 17, 2017

What is the full text of the error message? Also, are you getting it when you run this code, or when you click one of the links you're creating?

Inspiring
March 20, 2017

I only get the error message when I create the links. There is no more text than "GeneralError: Operation failed. Root.(null):Number:Batch undefined: Exce script terminated.

BTW: The code creates both links (and both work!), but subsequent commands are interrupted and the error message points to the setAction command.