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

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

Explorer ,
Mar 17, 2017 Mar 17, 2017

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?

TOPICS
Acrobat SDK and JavaScript , Windows
2.1K
Translate
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

Explorer , Mar 24, 2017 Mar 24, 2017

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!

Translate
Community Expert ,
Mar 17, 2017 Mar 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?

Translate
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
Explorer ,
Mar 20, 2017 Mar 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.

Translate
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
Community Expert ,
Mar 20, 2017 Mar 20, 2017

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

Translate
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
Explorer ,
Mar 20, 2017 Mar 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.

Translate
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
Community Expert ,
Mar 20, 2017 Mar 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.

Translate
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
Explorer ,
Mar 20, 2017 Mar 20, 2017

So it is not a folder-level JavaScript but a script which is run as action (sequence).
Anyhow: How can I prevent the error when running the batch sequence? What could be the reason for this error?

Translate
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
Community Expert ,
Mar 22, 2017 Mar 22, 2017

Did you get the error with any PDF file?

Translate
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
Explorer ,
Mar 22, 2017 Mar 22, 2017

This is the issue: The error occurs in about 80% of the cases, so not always.

BTW: Is it important to have a delay between import of the PDF file and the linking to the text?
If yes: How to implement the delay?

Translate
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
Community Expert ,
Mar 22, 2017 Mar 22, 2017

What happens when you remove the import of the PDF files?

Translate
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
Explorer ,
Mar 22, 2017 Mar 22, 2017

The rest of the program runs always smoothly if I remove the PDF import and the linking to the PDF file.

Translate
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
Community Expert ,
Mar 22, 2017 Mar 22, 2017

Remove only the PDF import.

Translate
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
Explorer ,
Mar 22, 2017 Mar 22, 2017

Same issue:

GeneralError: Operation failed.
Root.(null):3984:Batch undefined:Exec
script terminated

So the issue is not related to the PDF import.

Clicking the created link triggers (correctly) the error:

TypeError: Invalid argument type.
Doc.exportDataObject:1:Link:Page1:Annot14:Action1
===> Parameter cName.

Translate
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
Community Expert ,
Mar 22, 2017 Mar 22, 2017

On how many files do you use the action?

Translate
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
Explorer ,
Mar 22, 2017 Mar 22, 2017

I use the action only on the specific open PDF file.

The complete batch file (which creates checkboxes and adds attachments) is quite large, i.e., processing of the whole file takes about 2 Minutes (file size of the batch as SEQU file is about 150kB).

Is there any type of limitation due to memory resources?

Translate
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
Community Expert ,
Mar 23, 2017 Mar 23, 2017

Looks like a problem with setAction.

Translate
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
Explorer ,
Mar 24, 2017 Mar 24, 2017

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!

Translate
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
Community Expert ,
Mar 24, 2017 Mar 24, 2017

The reason for this may be that the method addLink changes the document.

Translate
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
Community Expert ,
Mar 24, 2017 Mar 24, 2017

I think you're right. Your loop is very strange. I don't understand the whole do-while section of it and the use of the "spc" variable. I think you don't need it at all, if I understand correctly what you're trying to do.

And no, adding a link does not change the file in a way that should interfere with this loop, since you're not adding actual text.

Translate
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
Explorer ,
Mar 24, 2017 Mar 24, 2017
LATEST

The reason for the do-while section is the command getPageNthWord. The command limits words by not only by a whitespace, but also e.g. by an underscore. Since I have to reference the whole filename, I have to find the complete string up to a real space char.

As the program "searches" the file extension, I have to step backwards through the text.

But again: This results from a routine which is not an optimal solution for my purpose. I rather have to search for the filename in the text, find the position in terms of "getPageNthWord".  I might therefore analyze the search string to retrieve the number of "sub-words" (see remark above) and directly apply the routing to get the boundary box on the first and last sub-word.

The processing of the two cascaded for-loops (jj, i) takes most of the time (the two minutes are required for a 50 page document with 90% of text per page).

Translate
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