4 Replies Latest reply on Sep 1, 2009 9:20 AM by ostranderbrown1

    Batch Export .indd files to .jpg using VB


      I need help.


      I am new at this and not entirely sure what I'm doing. I need to create a script that looks in a folder of .indd files, exports them to .jpg files (with the same name), closes the file, and moves on to do the next file, until all the files are done.


      I've figured out what's below, but I don't know how to create the loop for it to process all the files. Plus, I can't figure out how to change the extension, without changing the file name.


      Set myInDesign = CreateObject("InDesign.Application.CS2")
      myDocpath = "C:\Christopher\"
      myFile = "98649431a"
      myFiles = (myDocpath & myFile & myIDExtension)
      myIDExtension = ".indd"
      myJpegExtension = ".jpg"

      Set myDocument = myIndesign.Open(myFiles)

      myInDesign.ActiveDocument.Export "JPEG", myDocpath & myFile & myJpegExtension , False

      myDocument.close (idNo)


      Thank-you for any help,


        • 1. Re: Batch Export .indd files to .jpg using VB
          ostranderbrown1 Level 1

          An Edit to my original message. It seems that I can't get a higher resolution .jpg out of CS2 other than 72 dpi? Is this a glitch?


          Seems we are going to have to go with exporting.pdf files then, and perhaps learning some scripting for Acrobat to create the .jpg files.


          I found this script for Javascript but I need it converted to VB.




          //==== Batch PDF =====\\
          /* InDesign JavaScript to Create PDFs of a batch of InDesign files using an export PDF preset */

          var myPDFExportPreset = app.pdfExportPresets.item("test1"); // Change myPDFpreset to the name of the preset you want to use
          var myFileLocation = Folder.selectDialog("Please select path to files");

          myFolder = new Folder ([myFileLocation]);
          myFolderContents = myFolder.getFiles("*.indd"); // array
          myFileAmount = (myFolderContents.length - 1);

          // ===== Open, Export as PDF, and Close files ===== \\
          for (i = myFileAmount; i >= 0; i--)
          app.open(File (myFolderContents[i]));
            File(myFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0] + ".pdf"),

          • 2. Re: Batch Export .indd files to .jpg using VB
            [Jongware] Most Valuable Participant
            It seems that I can't get a higher resolution .jpg out of CS2 other than 72 dpi? Is this a glitch?


            Adobe just never imagined making the resolution a preference. For anything more advanced, exporting to PDF and post-processing in Photoshop is usually recommended. For a repeated action such as this, the recording Action option in PS is very useful (and that's yet another thing they might well add to ID).


            It seems the export-to-file works nicely for you, but you need help on

            1. getting a list of files in a certain folder,
            2. looping over this list,
            3. some string manipulation to get correct file names.

            All of these are done in the javascript version; they are "normal" VB operations, not specific to the InDesign Object model, so you could try a google for sample code or ask on a general VB forum. (That is, unless one of the resident VB scripters happen to pass by in the mean time.)

            • 3. Re: Batch Export .indd files to .jpg using VB
              ostranderbrown1 Level 1

              Here is my Script, now I just need some help on the VB to create a loop.


              'Open InDesign
              Set myInDesign = CreateObject("InDesign.Application.CS2")

              'Open Document
              Set myDocument = myInDesign.Open("C:\Christopher\TestFolder\98574418a.indd")

              'Save Location
              mySaveLocation = "C:\Christopher\Test.pdf"

              'Export to .pdf Using Preset
              myDocument.Export 1952403524, mySaveLocation, False, myInDesign.pdfExportPresets.item("test1")

              'Close Document
              myDocument.close (1852776480)




              • 4. Re: Batch Export .indd files to .jpg using VB
                ostranderbrown1 Level 1

                Ok folks, here is my finished script. This is for InDesign CS2, it will open all the .indd files in a directory, and convert them to a .pdf using a custom Pre-Set.


                I have another question about how to get .jpg files from the .pdf's to finish my project, but I'll post that in a new discussion.


                'Open InDesign
                Set myInDesign = CreateObject("InDesign.Application.CS2")

                'Save Location
                mySaveLocation = "C:\Christopher\PDF\"

                'Working folder
                myFolder = "C:\Christopher\TestFolder\"

                set fso = CreateObject("Scripting.FileSystemObject")
                set folder = fso.GetFolder(myFolder)


                for each file in folder.files
                  'check if this is an indd file
                  if Right(file.Name,Len(file.Name) - InStr(file.Name,".")) = "indd" then
                    'Open Document
                    Set myDocument = myInDesign.Open(myFolder&file.Name)
                    filename = file.Name
                    savename = fso.GetBaseName(filename)
                    savelocation = (mySaveLocation & savename & ".pdf")

                    'Export to .pdf Using Preset
                    myDocument.Export 1952403524, savelocation, False, myInDesign.pdfExportPresets.item("test1")

                    'Close Document
                    myDocument.close (1852776480)    
                  end if

                set fso = nothing
                set folder = nothing