1 Reply Latest reply on Dec 5, 2014 2:32 AM by steverocket2

    Export selectd text as a jpeg

    balagluck

      Please review my code, i am not able to get all the indesign files information as per my code, i can export only first two files, then the loop repeatedly process the second file only,not getting 3rd and 4th...., Please advice.

       

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

      app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;

      app.jpegExportPreferences.exportResolution = 300;

      app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.RGB;

      app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat .BASELINE_ENCODING;

       

      var myFolder=Folder.selectDialog("Select Indesign Folder");   

      var myInddFiles=myFolder.getFiles("*.indd");

      for(i=0; i<myInddFiles.length; i++){

         var myDoc=app.open (myInddFiles[i]);

         var myRuleSet = new Array (new sample);

          with (myDoc){

          var element = xmlElements;

          __processRuleSet (element[0], myRuleSet);

          } 

       

      function sample(){

          this.name = "sample";

          this.xpath = '//*[@font="Medicine Symbols 1"]';

          this.apply = function (myElement, myRuleProcessor){

           with(myElement){

            var myframe = myDoc.pages[0].textFrames.add();

              myElement.placeXML(myframe);

              myframe.fit(FitOptions.FRAME_TO_CONTENT);

              myframe.select();

              imageName = myElement.xmlAttributes.item('id').value+''        

              $.writeln (filepath = myFolder+"/"+imageName+".jpg");

              myframe.exportFile(ExportFormat.JPG,new File(filepath), false);

              }

          }

      }

       

      myDoc.close(SaveOptions.NO);

      }

        • 1. Re: Export selectd text as a jpeg
          steverocket2 Level 1

          Hi,

          I would not do the export of the frame within an XML rule.

          Without the export InDesign will create more than two frames.

           

          function sample(){

              this.name = "sample";

              this.xpath = '//*[@font="Medicine Symbols 1"]';

              this.apply = function (myElement, myRuleProcessor){

               with(myElement){

                var myframe = myDoc.pages[0].textFrames.add();

                  myElement.placeXML(myframe);

                  myframe.fit(FitOptions.FRAME_TO_CONTENT);

                  //myframe.select();

                  //var imageName = myElement.xmlAttributes.item('id').value''       

                  //$.writeln (filepath = myFolder+"/"+imageName+".jpg");

                  //myframe.exportFile(ExportFormat.JPG, new File(filepath), false);

                  }

              }

          }

           

          thanks Stefan