3 Replies Latest reply on Jul 13, 2012 4:44 AM by Muppet Mark

    Convert Image Using Script (JSX)

    Harsh V Sharma

      Hi All,


      I want to convert a AI file into a JPEG by using JSX(java script)

      i am able to change its file type but having some problem with resizing

      can anyone please suggest me some solution.



        • 1. Re: Convert Image Using Script (JSX)
          Muppet Mark Level 5

          You can easily export a document to *.jpeg format using extendscript… There are options for horizontal and vertical scales what you can't alter by script is the resolution always 72dpi

          • 2. Re: Convert Image Using Script (JSX)
            Harsh V Sharma Level 1

            Thanks Mark


            But i want to change the size of input AI while converting it to JPEG

            this is all i want to do.


            i am using the following code:


            var docRef = app.activeDocument;

            var srcFile = app.activeDocument.fullName;

            var dstFile = app.activeDocument.path+"/"+app.activeDocument.name;

            //var dstFile = "D:/"+app.activeDocument.name;

            var ej = new ExportOptionsJPEG();

                ej.Optimization = true;

                ej.QualitySetting = 60;


            for(var i=0; i<docRef.rasterItems.length;i++)





            docRef.exportFile(new File (dstFile), ExportType.JPEG, ej);


            but i am not sure this will work in every condition.

            i need a  perfect solution for it because some AI files mightnot have RasterItems in it, that will create a problem while resizing the document.


            Please guid me.



            • 3. Re: Convert Image Using Script (JSX)
              Muppet Mark Level 5

              I don't understand what exactly you are doing here? You have created a loop but only change the first raster[0]… you export after the loop so only one file… There are option to size in the export and you have not used them. I think a better description or a screen grab would help…