Skip to main content
Ramjivk
Inspiring
August 8, 2011
Question

Export all open docs as PDF

  • August 8, 2011
  • 3 replies
  • 2847 views

I am working on a script which should export all the open docs as PDF.

I use the following script to export. but InDesign does not export all the PDF. Assume, I have opened seven docs and the script exports only 4 docs and again come back to the first exported doc. can any one help how to resolve the issue.

var myTotalDocs = (app.documents.length);

    for(var i = 0; i < myTotalDocs; i++)

    {

        myDocument = app.documents;

        app.activeDocument = myDocument;

        var myFilePath = app.activeDocument.filePath;

       app.activeDocument.exportFile(ExportFormat.pdfType, File(myFilePath+"/"+".pdf"),false);

}

Thanks

This topic has been closed for replies.

3 replies

Ramjivk
RamjivkAuthor
Inspiring
August 8, 2011

Thanks for the support

csm_phil
Legend
August 8, 2011

Hi Ramjivk,

Please try the below JS Code, i hope you expected this!

while(app.documents.length>0){
     var myDoc = app.activeDocument;
     myDoc=myDoc.filePath+"/"+myDoc.name.split(".indd").join(".pdf");
     //alert(myDoc);
     var exportfile=new File(myDoc);
     app.activeDocument.exportFile(ExportFormat.pdfType, exportfile, false);
     app.activeDocument.close();
     }

thx

csm_phil

Ramjivk
RamjivkAuthor
Inspiring
August 8, 2011

Hi csm_phil,

Thank you so much. Its working.

It will be great if you can explain what could be the problem?

Regards

Ramji V K

Jongware
Community Expert
Community Expert
August 8, 2011

Ramjivk wrote:

It will be great if you can explain what could be the problem?

If you have seven documents and you close the first one after processing, what are the array indexes of the ones left?

(None of the above posters got it right; cms_phil avoided this problem.)

Adobe-InDesign_CS4
Inspiring
August 8, 2011

Dear Ramji


Please use the below code for solving your problem:


//===================== Start : Export =================================//

var myTotalDocs = (app.documents.length);

    for(var i = 0; i < myTotalDocs; i++)
    {

        myDocument = app.documents;
        app.activeDocument = myDocument;
        var myFilePath = app.activeDocument.filePath;

       app.activeDocument.exportFile(ExportFormat.pdfType, File(myFilePath+"/"+".pdf"),false);
    myDocument.close(SaveOptions.NO);

}


//===================== End: Export =================================//


Once Export the InDesign open document then immediatly close... otherwise this problem [what you menditoned] will occure.


Thanks & Regards

T.R.Harihara SudhaN

Ramjivk
RamjivkAuthor
Inspiring
August 8, 2011

I have tried the code, but it throws an error message

Error number: 30477

Error string: Invalid value for set property "activeDocument". Expected Document, but received nothing.

Source: app.activeDocument = myDocument;

Please help