14 Replies Latest reply on Mar 2, 2016 1:38 AM by williamh30699131

    [JS][CS4]List fonts used in the Document

    chrlsdrwn12 Level 1

      Hi to all scripting gurus,

       

      I have this following script that returns a list of fonts used in the document:

      function fontused(){        

            var fontscoll = document.fonts;         

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

                var font = fontscoll[i];            

                alert(font.name);          

           }

      }

      The above is working OK my problem is that it also list the fonts used in the placed illustrator files (.eps). Is there some kind of parameter or something that i can use so that it only list the fonts used in the text?

       

      -CharlesD

        • 1. Re: [JS][CS4]List fonts used in the Document
          Trevorׅ Adobe Community Professional

          Hi Charles

           

          Try this

          var  myDocFonts=app.documents[0].stories.everyItem().textStyleRanges.everyItem().appliedFont,
                  l = myDocFonts.length, myFonts="";
                  uniqueFonts = {}, n;
          while (l--) uniqueFonts[myDocFonts[l].name] = myDocFonts[l].name;
          for (n in uniqueFonts) myFonts+=(uniqueFonts[n])+"\r";
          alert(myFonts)
          

           

          Trevor

          • 2. Re: [JS][CS4]List fonts used in the Document
            chrlsdrwn12 Level 1

            Hi Trevor,

             

            Thanks for this. I had to delete: ", n" coz its returning an error string: n is undefined. Its running OK now. Any thoughts on why i had to delete that part?

            • 3. Re: [JS][CS4]List fonts used in the Document
              Trevorׅ Adobe Community Professional

              Hi Charles,

               

              The ",n" caused an error because of the ";" "after myFonts=""" the ";" there should have been a "," as I meant to declare all the variables from "l" to "n" as a var.  By having the ";" the "uniqueFonts = {}, n;" becomes detached from the var and the statement about the "n" becomes completely meaningless. The equivalent of having "Hello there" written in the middle of the script, thus throwing an error. It was a typo, sorry about that

               

              Either way Glad to help,

               

              Trevor

              • 4. Re: [JS][CS4]List fonts used in the Document
                chrlsdrwn12 Level 1

                Hi Trevor,

                 

                I get it now. l - n should have been one liner. I modified the script and replaced " with , and its ok now... Thanks again!

                 

                -CharlesD

                • 5. Re: [JS][CS4]List fonts used in the Document
                  David W. Goodrich Level 3

                  Maybe I didn't get the changes right, but when I tried this JSX code on three recent files it twice reported fewer fonts than IDCS4's Find Font.

                   

                  David

                  • 6. Re: [JS][CS4]List fonts used in the Document
                    Trevorׅ Adobe Community Professional

                    Hi David

                     

                    I would guess one of two things

                     

                    1) That's the point of the script, not to list the fonts that are included in the placed parts of the document.

                    2) There are fonts that are not used  in the active text or for other reasons that if you actually try to find them with the Find font or with a Grep search you won't find them even if hidden/locked layers etc. are also searched

                    See also screen shot below

                    ScreenShot087.png

                    • 7. Re: [JS][CS4]List fonts used in the Document
                      David W. Goodrich Level 3

                      Hi Trevor,

                       

                      I should have been more specific.  My test files have no placed artwork, no hidden text, and just one layer.  Moreover, Find Font reports all of the un-reported fonts are included in the definitions for various character styles.  The common denominator is that the un-reported fonts occur only in footnotes.

                       

                      I don't grasp the details, but I realize footnotes are a kind of odd-ball text in ID, as are tables.  So I wasn't too surprised to find that the JSX in question seems not to report fonts used in tables either.  Everybody's work differs, of course, but I see a lot of footnotes and tables -- and I re-learned the point that these are "special" text.

                       

                      David

                      • 8. Re: [JS][CS4]List fonts used in the Document
                        chrlsdrwn12 Level 1

                        Hi Trevor,

                         

                        Tried it and yes it doesn't go over tables and footnotes. Any idea how do we address this? I'll try to modify the script myself see how much i learned...

                         

                        Thanks for bringing this up David.

                         

                        -CharlesD

                        • 9. Re: [JS][CS4]List fonts used in the Document
                          Trevorׅ Adobe Community Professional

                          Hi Chales

                           

                          I'm going out now, I'll post an answer in a few hours

                          • 10. Re: [JS][CS4]List fonts used in the Document
                            chrlsdrwn12 Level 1

                            Ok we'll wait for that... Thank you very much Trevor...

                            • 11. Re: [JS][CS4]List fonts used in the Document
                              Trevorׅ Adobe Community Professional

                              Charles

                               

                              Doesn't time fly?

                               

                              This will give you the idea, if when you find more exceptions add them in a likewise manner.

                              The "if" statements check that tables, headers, etc. exists otherwise an error will be throw.

                               

                              Enjoy

                              Trevor

                               

                              P.s. I had planned on updating the script after David highlighted the problem, just didn't get round to it.

                               

                              // Script to find fonts in documents which are not just in content pasted from illustrator file
                              // By Trevor http://forums.adobe.com/message/4807396#4807396
                              var   myFonts="",
                                      uniqueFonts = {}, n;
                              if (app.documents[0].stories.everyItem().textStyleRanges.length > 0) fontsIn (app.documents[0].stories.everyItem().textStyleRanges.everyItem().appliedFont)        
                              if (app.documents[0].stories.everyItem().tables.length > 0) fontsIn (app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().textStyleRanges.everyItem().appliedFont)
                              if (app.documents[0].stories.everyItem().footnotes.length > 0) fontsIn (app.documents[0].stories.everyItem().footnotes.everyItem().textStyleRanges.everyItem().appliedFont)
                              for (n in uniqueFonts) myFonts+=(uniqueFonts[n])+"\r";
                              alert(myFonts)
                              function fontsIn (item)
                                  {
                                      var l = item.length;
                                      while (l--) uniqueFonts[item[l].name] = item[l].name;
                                   }
                              
                              1 person found this helpful
                              • 12. Re: [JS][CS4]List fonts used in the Document
                                chrlsdrwn12 Level 1

                                Hi Trevor,

                                 

                                That nailed it! Thank you very much!

                                 

                                @David

                                Thanks for the feedback. You might wanna try the script one more time see if there's anything you wanna add...

                                 

                                -CharlesD

                                • 13. Re: [JS][CS4]List fonts used in the Document
                                  David W. Goodrich Level 3

                                  This worked perfectly on my test files -- thank you very much!

                                   

                                  Only because you asked, the one thing I might add would be a count of the fonts: when you get more than 10 or 12 it's not so convenient to compare screen-grabs of new and old.  But maybe that's best left as a confidence-building exercise for those like me who have very limited JSX skills.

                                   

                                  David

                                  • 14. Re: [JS][CS4]List fonts used in the Document
                                    williamh30699131 Level 1

                                    Stumbled upon this script while trying to find a way to identify fonts across multiple files without opening them in the first place.

                                    Is there anyway this script can be edited to do that?

                                     

                                    For instance if i have 10 files and 8 of them use arial - bold, it will come up saying arial - bold (8)

                                     

                                    any help would be appreciated, running windows if that helps