5 Replies Latest reply on Oct 23, 2012 6:05 AM by [Jongware]

    [JS][CS4]Export selected characters into image

    chrlsdrwn12 Level 1

      Hi sripting gurus,


      There is this document that has thousands of chinese characters and i need to find all those characters and export into .tif file format. Any idea on how to make this task easier by way of scripting?



        • 1. Re: [JS][CS4]Export selected characters into image
          chrlsdrwn12 Level 1

          So I'm seeing some light here the workflow might be:


          1. find chinese characters by setting the preference into a specific font which is Simsun

          2. the find item should then be placed into its own frame

          3. select the created frame then export as jpeg by choosing the option 'Selection'

          4. save the jpeg into a specific folder somewhere

          5. loop


          Help me start to build the script piece by piece guys...



          • 2. Re: [JS][CS4]Export selected characters into image
            [Jongware] Most Valuable Participant

            No problem at all. You don't need even to export a "selection", you can export any object you can get a handle to.

            This follows your suggestion line by line:


            app.findTextPreferences = null;
            app.findTextPreferences.appliedFont = "SimSun";
            app.jpegExportPreferences.resolution = 300;
            list = app.activeDocument.findText();
            for (i=0; i<list.length; i++)
             tempframe = app.activeDocument.textFrames.add();
             tempframe.geometricBounds = [ tempframe.geometricBounds[0],
              tempframe.geometricBounds[3]+10 ];
             list[i].duplicate(LocationOptions.AT_BEGINNING, tempframe.texts[0]);
             tempframe.exportFile (ExportFormat.JPG, File(Folder.myDocuments+"/img_"+i+".jpg"));


            .. and running it on some random Chinese text gives me "img_0" and "img_1", in 300 dpi resolution (you didn't specify that, but I assume you'd prefer this over the default rez of 72 dpi!).



            • 3. Re: [JS][CS4]Export selected characters into image
              [Jongware] Most Valuable Participant

              Ow -- I forgot something.


              If you create a new text frame, it gets the default size of 10 pt x 10 pt. Now I don't know how big your Chinese text is, but for anything larger than this -> ∙ it will be too small, and copying the text into it will make all of it overset.


              Unfortunately Fit Frame To Content works as expected for images, but not for overset text. The text frame will never grow, only shrink.

              So we have to initially make the text frame large enough and then use Fit Frame. How much larger does the frame needs to be? I dunno. I just add "10" to the existing size, and for me that's "10 mm", large enough for two single Chinese ideograms at 12 pts.


              If you have a much larger font size, or much more characters, you need more space -- in millimeters. If you are working in inches, adding "10" ought to be enough; on the other hand, if you are working in points, you need to add way more.

              • 4. Re: [JS][CS4]Export selected characters into image
                chrlsdrwn12 Level 1

                Hi Jongware,


                Thanks for this awesome script. Here's a bug though, i tried running it with multiple instances and when the multiple characters are split in two (some characters moved down to the next line) it creates 3 different images, one with the whole set, the other image is the set on the first and the other one is the set that has been on the next line. Any thoughts?



                • 5. Re: [JS][CS4]Export selected characters into image
                  [Jongware] Most Valuable Participant

                  Hmm, now that's unexpected behavior. The Find Text command ought to see only a single continuous set -- even if the original text was split over two or more lines.


                  .. Anyone?