8 Replies Latest reply on Oct 5, 2013 12:17 AM by csm_phil

    Export all open docs as PDF

    Ramjivk

      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[i];

              app.activeDocument = myDocument;

              var myFilePath = app.activeDocument.filePath;

       

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

       

      }

       

      Thanks

        • 1. Re: Export all open docs as PDF
          Adobe-InDesign CS4 Level 1

          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[i];
                  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

          • 2. Re: Export all open docs as PDF
            Ramjivk Level 1

            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

            • 3. Re: Export all open docs as PDF
              csm_phil Level 4

              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

              1 person found this helpful
              • 4. Re: Export all open docs as PDF
                Ramjivk Level 1

                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

                • 5. Re: Export all open docs as PDF
                  Ramjivk Level 1

                  Thanks for the support

                  • 6. Re: Export all open docs as PDF
                    [Jongware] Most Valuable Participant

                    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.)

                    1 person found this helpful
                    • 7. Re: Export all open docs as PDF
                      Ramjivk Level 1

                      Hi Jongware,

                       

                      I removed the below code from the script.

                       

                      var myTotalDocs = (app.documents.length);


                      so, i will not have any array. If i have seven docs, i export the first doc as PDF and close that. so that InDesign does not export the same doc again and again.

                       

                      thanks.

                      1 person found this helpful
                      • 8. Re: Export all open docs as PDF
                        csm_phil Level 4

                        Hi Ramjivm,

                         

                        I think the problem is forward loop, If you use the reverse loop the problem is solved.

                         

                         

                        var myTotalDocs = (app.documents);
                        for(var i = myTotalDocs.length-1; i>=0; i--){
                            myDocument = app.documents[i];
                            app.activeDocument = myDocument;
                            var myFilePath = String(app.activeDocument.fullName);
                            app.activeDocument.exportFile(ExportFormat.pdfType, new File(myFilePath.replace(".indd", ".pdf")),false);
                            app.activeDocument.close();
                            }
                        

                         

                        thx,

                        csm_phil

                        1 person found this helpful