4 Replies Latest reply on Jun 19, 2013 5:39 AM by Gustavo Del Vechio

    Export all pages to JPG

    Gustavo Del Vechio Level 3

      Hi friends


      I use to write scripts for Photoshop, Bridge and Illustrator. But it´s my firt time writting scripts to Adobe InDesign (and my first to this forum too). I´m accustomed with the JavaScript referece document of that 3 softwares, so I´m getting a direct help via the "Object Model Viewer" inside Extended Script Toolkit for writting with InDesign.


      I want to export all the pages of my document using JPG as file format. So I set the properties to an instance of JPEGExportPreference and would like to use this configuration to export all the pages. Am I right to use the method app.activeDocument.exportFile() ??


      Because I did not find a place to declare the method to read my JPG preference. It´s also getting an error page range was not set. Could you analyse my code and see what I´m missing?


      Thank you very much:




      var myDoc = app.activeDocument;


      var fName = myDoc.name.slice (0, myDoc.name.lastIndexOf ("."));

      var oFolder = new Folder (myDoc.filePath + "/" + fName + " (Exported)");

      if (! oFolder.exists){




      var fOutput = new File (oFolder + "/" + fName + ".jpg");


      var opJPG = new JPEGExportPreference();

      opJPG.antiAlias = true;

      opJPG.embedColorProfile = true;

      opJPG.exportResolution = 300;

      opJPG.jpegColorSpace = JpegColorSpaceEnum.RGB;

      opJPG.jpegExportRange = ExportRangeOrAllPages.EXPORT_ALL;

      opJPG.jpegQuality = JPEGOptionsQuality.HIGH;

      opJPG.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;

      opJPG.simulateOverprint = true;

      opJPG.useDocumentBleeds = false;



      myDoc.exportFile(ExportFormat.JPG, fOutput, false);

        • 1. Re: Export all pages to JPG
          Laubender Adobe Community Professional & MVP

          @Gustavo – see the following function by Manu at www.hilfdirselbst.ch:




          For DOM documentation see:





          1 person found this helpful
          • 2. Re: Export all pages to JPG
            Gustavo Del Vechio Level 3

            Hi Laubender


            Thank you very much for the informations.

            I analyzed the Manu´s function and it has near the same parameters as what I´ve wrote (he, at true, exports a range of pages in the main function).


            In my side, If I run my own code (as shown in the fist message here), then InDesign returns this error: "Failed to export the JPEG file. Invalid page number specified."


            But I´m telling to export all pages!! hehe


            Am I missing anything?


            Thank you very much for the help.


            • 3. Re: Export all pages to JPG
              [Jongware] Most Valuable Participant

              Gustavo, other than in Illustrator (don't know about PS and Bridge), in InDesign scripts you cannot "create" new objects using this notation:


              var opJPG = new JPEGExportPreference();


              Try a with .. statement instead to directly modify the existing object:


              with (app.jpegExportPreferences)
                antiAlias = true;
                embedColorProfile = true;
                .. etc.


              (I know, there are lots of articles that claim "with statement considered harmful", but for this particular case I don't see why , as it is just a shortcut for writing


              app.jpegExportPreferences.antiAlias = true;
              app.jpegExportPreferences.embedColorProfile = true;
              .. app.jpegExportPreferences.etc.


              .. and so on.)

              • 4. Re: Export all pages to JPG
                Gustavo Del Vechio Level 3

                Ah Thank you very much Jong!


                This worked!!! I was really thinking like the exportation in Illustrator, there you create a new instance for an ExportOptionsJPEG object and use this as parameters for exporting!


                Here in Indesign you just set the properties for the app!



                Thank you very much. By the way, I´ve just take a look at your documentation Laubender mentioned, and it´s a good job! Congratulations