7 Replies Latest reply on Dec 7, 2012 6:05 AM by BEGINNER_X

    Need Document Fonts in .TXT format

    BEGINNER_X Level 3

      Hi All,

       

      I am trying a script which is in "InDesignCS3_ScriptingGuide_JS" related to font list.

       

      My requirement:

       

      How can we get documents font list in .txt format.

       

       

      Trying Code is below:

       

      //To display font name (working fine)

       

      var myDocument = app.activeDocument

       

      var myDocumentFontNames = myDocument.fonts.everyItem().getElements();

       

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

       

      alert(myDocumentFontNames[i].name);

       

      }

       

      //i think here is doubt


      var myFileName = "~/Desktop/Test.txt";

       

      myDocumentFontNames.exportFile(ExportFormat.taggedText, File(myFileName));

       

       

      Can anyone give solution for me if you willing.

       

       

      Thanks in advance

       

      BEGINNER

        • 1. Re: Need Document Fonts in .TXT format
          csm_phil Level 4

          Hi BEGINNER,

           

          Once again, you doing same wrong method. I am already instruct to you in the below web link.

           

          http://forums.adobe.com/message/4882727#4882727

           

          Now, also you doing same, Have you seen the export options export the font family names in the text file. Please try you manully it will works after you approach in script.

           

          thx,

          csm_phil

          • 2. Re: Need Document Fonts in .TXT format
            Cenchen Level 2

            @beginner

             

            Try this,

             

             

                          

            var myDocument = app.activeDocument

            var fontList = []

            var myDocumentFontNames = myDocument.fonts.everyItem().getElements();

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

            fontList.push(myDocumentFontNames[i].name);

            }

            fontList = fontList.toString().replace(/,/g,"\n").replace(/\t/g," ")

            var myFileName = File("~/Desktop/Test.txt")

            myFileName.open("w")

            myFileName.write(fontList)

            myFileName.close();

            1 person found this helpful
            • 3. Re: Need Document Fonts in .TXT format
              fabianmoronzirfas Level 1

              Try modifying this script that exports all app.fonts into a .txt file

               

              https://github.com/fabiantheblind/auto-typo-adbe-id/wiki/Fonts

               

              get the raw code here

               

              https://raw.github.com/fabiantheblind/auto-typo-adbe-id/master/fabiantheblind/fontslist.js x

               

              replace all

               

              app.fonts

               

              with

               

              app.activeDocument.fonts

               

               

              Cheers

              :fabian

              • 4. Re: Need Document Fonts in .TXT format
                BEGINNER_X Level 3

                Hi Cenchen, fabion and csm_phil,

                 

                Thanks a lot. Its working fine.

                 

                Could you explain detailed where i highlighted in BOLD.

                 

                 

                var myDocument = app.activeDocument

                 

                //What it is []

                var fontList = []


                var myDocumentFontNames = myDocument.fonts.everyItem().getElements();

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

                fontList.push(myDocumentFontNames[i].name);

                }

                 

                //Please explain this line very particularly

                 

                fontList = fontList.toString().replace(/,/g,"\n").replace(/\t/g," ")

                 

                 

                var myFileName = File("~/Desktop/Test.txt")

                 

                myFileName.open("w")

                myFileName.write(fontList)


                myFileName.close();

                 

                 

                Thanks in advance

                BEGINNER

                • 5. Re: Need Document Fonts in .TXT format
                  [Jongware] Most Valuable Participant

                  This clearly exposes your weakest point. You need to know basic Javascript before you can specifically write something for InDesign.

                   

                  The parts you highlight are plain, regular Javascript; nothing special. They are covered in any Javascript tutorial. Explaining them wouldn't take much time, but teching basic Javascript is not really the target of the InDesign scripting forum.

                  • 6. Re: Need Document Fonts in .TXT format
                    Laubender Adobe Community Professional & MVP

                    @BEGINNER – you need not to loop through "fontList", because with everyItem() you already get something that you can change directly into a string:

                     

                    var fontNameListString = app.activeDocument.fonts.everyItem().name.join();
                    

                     

                    With "join()" you get a String object that concatenates every single contents of the array. The delimiter between the substrings is a "," by default. You could choose another one:

                     

                    var fontNameListString = app.activeDocument.fonts.everyItem().name.join("\n");
                    

                     

                    In the case above a newline character will injected. "\r" for a paragraph sign would also do.
                    Now every single font name is either in a new line or in a new paragraph.

                     

                    Oh. And you have to know, that the name of a font consists of two parts: the family and the style. And the two parts are devided by a tab-character which is represented by "\t".

                     

                    Example:

                     

                    Univers 47     Light Condensed

                     

                    For legibility or any other reason you could choose to replace all tabs with something else, e.g. a blank.

                     

                    var fontNameListString = app.activeDocument.fonts.everyItem().name.join("\n").replace(/\t/g,"");
                    

                     

                    The replace() function can take a regular expression like /\t/g, which means look for all tabs globally. Then comes the part with what you like to replace. This is a string that consists of only one blank.

                     

                    So with the last line of code you get a string like that:

                     

                    Univers 47 Light Condensed

                    Univers 67 Bold Condensed

                    Univers 59 Ultra Condensed

                    Arial Narrow Bold

                    Arial Narrow Regular

                     

                    And now you need a text file or something else, how about a text frame in InDesign, to feed that string as contents.

                     

                    Example:

                     

                    var fontNameListString = app.activeDocument.fonts.everyItem().name.join("\n").replace(/\t/g,"");
                    
                    app.activeDocument.textFrames.add({
                         geometricBounds:[0,0,100,100],
                         contents:fontNameListString
                         });
                    

                     

                    Without specifying on what specific page the text frame should be added, it's always done on page one.

                     

                    Uwe

                    • 7. Re: Need Document Fonts in .TXT format
                      BEGINNER_X Level 3

                      Hi Laubender and ALL,

                       

                      Thank you so much....

                       

                      Now i understand fully.

                       

                      Again thanks a lot.

                       

                       

                      Regards

                       

                      BEGINNER