Skip to main content
SilverNickels
Inspiring
April 10, 2018
Answered

Invalid File Specification Object

  • April 10, 2018
  • 1 reply
  • 5495 views

I am attempting to export the meta-data about the files contained in a PDF portfolio. I am using the code below which I copied from this link.

// code follows

var d = this.dataObjects;

var csv = '';

    if (d) {

    cfl = this.collection.fields.length;

    tx_cols = new Array();

    tx_names = new Array();

    for (i = 0; i < cfl; i++) {

      tx_cols.push(this.collection.fields.text);

      tx_names.push(this.collection.fields.name);

    }

        csv = tx_cols.join() + "\r\n";

        for (var i = 0; i < d.length; i++) {

      tx_data = new Array();

      for (var r = 0; r < cfl; r++) {

        tx_data.push("\"" + d.getFieldValue(tx_names) + "\"");

//     tx_data.push(d.getFieldValue(tx_names));                    .ast replaced this line w above

      }

      csv += tx_data.join() + "\r\n";

    }

    this.createDataObject({cName:"EmailData.csv", cValue:csv,cMIMEType:'text/csv'});

    this.exportDataObject("EmailData.csv");

    this.removeDataObject("EmailData.csv");

    }

// end of code

I am able to execute it but I receive this error:

RaiseError: Invalid file specification object.

Data.getFieldValue:31:Console undefined:Exec

===> Invalid file specification object.

undefined

I haven't worked with JavaScript previously so I will be looking at the Adobe docs but, since this it time critical, I was hoping not to have to work thru everything from the beginning. Does anyone have any suggestions where to begin? I am using Acrobat Pro DC.

Thank you,

This topic has been closed for replies.
Correct answer Thom Parker

I have modified the code so so that it just opens and closes the embedded document and outputs information to a report so I can determine how far it gets in the process. The script completes if I code it to open and close the first 200 or so embedded documents but it starts failing as I approach 220 embedded documents.

I have hard coded different starting points in the embedded documents and achieved similar results so I don't believe it is a single document that is causing the error.

If I don't open the embedded document, I can execute the loop for the count of the embedded documents without error.

Is there a statement that needs to be executed after an embedded document is closed to release resources consumed when when the document is opened?

Here is my current test code:

var d = this.dataObjects;

var rep = new Report();

    if (d) {

        cfl = this.collection.fields.length;

        tx_cols = new Array();

        tx_names = new Array();

        for (i = 0; i < cfl; i++) {

            tx_cols.push(this.collection.fields.text);

           

            rep.writeText("i = " + i + " fields.text = " + this.collection.fields.text);    //

            tx_names.push(this.collection.fields.name);

           

            rep.writeText("i = " + i + " fields.name = " + this.collection.fields.name);    //

        }   

        csv = tx_cols.join() + "\r\n";

        rep.writeText("d.length is " + d.length);

       

//        for (var i = 0; i < d.length; i++) {

        for (var i = 200; i < 400; i++) {           

//            tx_data = new Array();

            var oDoc = this.openDataObject(d.name);

            rep.writeText("i is " + i + " Embedded File name is " + oDoc.name);

           

            oDoc.closedoc

         

//            for (var r = 0; r < cfl; r++) {

               

//              tx_data.push("\"" + oDoc.getFieldValue(name:tx_names) + "\"");

//              tx_data.push(d.getFieldValue(tx_names));                    .ast replaced this line w above

//            }

//        csv += tx_data.join() + "\r\n";

       

        }

       

        rep.writeText("Embedded Doc loop is complete");

    }

       

    var docRep = rep.open("This is a test");

   

//    rep.writeText("Summary of files within the PDF portfolio: " + this.documentFileName + "\n");


There is an error in the code. The open documents are not being closed.

this line:

oDoc.closedoc

Needs to be this:

oDoc.closeDoc(true);

1 reply

Thom Parker
Community Expert
Community Expert
April 10, 2018

The data object is not the document object for the embedded file. so of course it cannot be used to call getField. To get the document object you have to open it with the "doc.openDataObject()" function.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
SilverNickels
Inspiring
April 11, 2018

Thanks for your reply. I have modified the code as below. It appears to be creating a Doc object from the embedded document but I get this error when I run the script:

RaiseError: Cos document table full.

Doc.openDataObject:30:Console undefined:Exec

===> Cos document table full.

undefined

I found several articles where the problem was reported but not a clear resolution. Do you have any suggestions?

// code follows

var d = this.dataObjects;

var csv = '';

    if (d) {

    cfl = this.collection.fields.length;

  

//    app.alert("collection field lenght is " + cfl)

    tx_cols = new Array();

    tx_names = new Array();

    for (i = 0; i < cfl; i++) {

      tx_cols.push(this.collection.fields.text);

      tx_names.push(this.collection.fields.name);

    }

        csv = tx_cols.join() + "\r\n";

        for (var i = 0; i < d.length; i++) {

          tx_data = new Array();

          var oDoc = this.openDataObject(d.name);

    

          for (var r = 0; r < cfl; r++) {

              

//            tx_data.push("\"" + oDoc.getFieldValue(name:tx_names) + "\"");

//            tx_data.push(d.getFieldValue(tx_names));                    .ast replaced this line w above

            }

          oDoc.closedoc

          csv += tx_data.join() + "\r\n";

        }

//  this.createDataObject({cName:"EmailData.csv", cValue:csv,cMIMEType:'text/csv'});

//  this.exportDataObject("EmailData.csv");

//  this.removeDataObject("EmailData.csv");

    }

// end of code

Thom Parker
Community Expert
Community Expert
April 11, 2018

Do you know at what point the error occurs?  Is it on the first embedded file opened? or somewhere down the line?  Is the Portfolio very large? Are there a lot of other files open? 

The message seems to indicate that the "document table" has run out of memory, meaning there is too much going on. Of course it may be that just one bad thing is going on and the reported error doesn't represent the actual error condition. For example, are all the embedded files PDFs? Are there any issues with the embedded PDFs?

Try simplifying the code to a loop that just opens and closes the embedded files, see if you get the same error.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often