21 Replies Latest reply on Apr 23, 2018 1:58 AM by Laubender

    Collect used fonts

    tpk1982 Level 4

      Hello,

       

      Is it possible to collect the used fonts in the active document?

       

      Tried coding:

       

      var  myFonts=app.documents[0].stories.everyItem().textStyleRanges.everyItem().appliedFont;
        len = myFonts.length;  
      var  destFolder = "~/Desktop/usedFonts/";  
      if ( !Folder(destFolder).create() ){ exit();  }
      
      
      while (len-->0) {  
        myfontpath = myFonts[len].filePath;  
        currFile = File( destFolder + File(myfontpath).name );  
        if ( !currFile.exists && File(currLinkFName).exists )  
        myfontpath[len].copyLink(currFile);  
        }  
      
      

      Regards,

      K

        • 1. Re: Collect used fonts
          Peter Kahrel Adobe Community Professional & MVP

          Yes, should be possible. What's the problem with your code?

           

          P.

          • 2. Re: Collect used fonts
            tpk1982 Level 4

            Hi Peter,

             

            Thank you for your reply. The problem is, it is not collecting the fonts as expected.

             

            I am not sure we can take the fonts using filePath, because it will work for images.

             

            var  myFonts=app.documents[0].stories.everyItem().textStyleRanges.everyItem().appliedFont;  
              len = myFonts.length;    
            var  destFolder = "~/Desktop/usedFonts/";    
            if ( !Folder(destFolder).create() ){ exit();  }  
                
            while (len-->0) {    
              myfontpath = myFonts[len].filePath;    
              currFile = File( destFolder + File(myfontpath).name );    
              if ( !currFile.exists)    
              myfontpath[len].copy(currFile);    
              }    
            

             

             

            Regards,

            K

            • 3. Re: Collect used fonts
              Peter Kahrel Adobe Community Professional & MVP

              Well, if you check one of the object-model viewers, you'll see that 'font' doesn't have the property 'filePath'. Try 'location'. Also, to get a handle on the fonts you can use

               

              myFonts = app.documents[0].fonts.everyItem().getElements();

               

              Getting them from the textStyleRanges gives you multiple instances of each font, so your script ends up doing all kinds of unnecessary things. And finally, when you know the length of what you're processing it's better to use a for-loop, that's quicker than a while-loop. Though on modern computers you don't notice the difference much anymore.

               

              Peter

              1 person found this helpful
              • 4. Re: Collect used fonts
                tpk1982 Level 4

                Thanks Peter, i will try as you adviced

                • 5. Re: Collect used fonts
                  tpk1982 Level 4

                  Hello Peter,

                   

                  I tried the below coding and it is also not copying the fonts

                   

                  var  myFonts = app.documents[0].fonts.everyItem().getElements();
                  len = myFonts.length;    
                  var  movefolder = "~/Desktop/usedFonts/";      
                      for(i=0;i<len;i++){
                      movefolder = Folder(movefolder);   
                      if (!movefolder.exists) movefolder.create();  
                          if (movefolder.exists){
                              myFonts[0].copy(movefolder);  
                          }
                      }
                  

                   

                  Thanks,

                  K

                  • 6. Re: Collect used fonts
                    Jump_Over Level 5

                    Hi,

                     

                    Notice that a file is the target - not a font.

                     

                    var 
                      myFonts = app.documents[0].fonts.everyItem().getElements(),
                      len = myFonts.length, 
                      cFile, cName, outFile, i,
                      movefolder = "~/Desktop/usedFonts/",
                      movefolder = Folder(movefolder);   
                    if (!movefolder.exists) movefolder.create();
                    
                    for(i=0;i<len;i++) { 
                      cFile = File(myFonts[i].location);
                      if(!cFile.exists) continue;
                      cName = cFile.name;
                      outFile = File(movefolder + "/"+ cName);
                      cFile.copy(outFile);   
                      } 
                    

                     

                    Jarek

                    • 7. Re: Collect used fonts
                      Peter Kahrel Adobe Community Professional & MVP

                      No need to create the movefolder multiple times. And the destination is a file path, not a string:

                       

                      var myFonts = app.documents[0].fonts.everyItem().getElements();
                      var len = myFonts.length;
                      var movefolder = "~/Desktop/usedFonts/";
                      if (!movefolder.exists) Folder (movefolder).create();
                      for (var i=0;i<len;i++) {
                        var name = File(myFonts[i].location).name;
                        File (myFonts[i].location).copy(File(movefolder+'/'+name));
                      }
                      

                       

                      P.

                       

                      (Jarek beat me to it!)

                      1 person found this helpful
                      • 8. Re: Collect used fonts
                        tpk1982 Level 4

                        Thank you Jarek.. It is working fine..

                        • 9. Re: Collect used fonts
                          tpk1982 Level 4

                          Thank you Peter.. Your's also working good..

                           

                          Thanks again for your timely help..

                           

                          Hereafter forum should have the facility to give correct answer option for two or more people..

                          • 10. Re: Collect used fonts
                            q3player Level 1

                            I just stumbled upon this old threat and encountered a problem using the scripts:

                             

                            - works fine with TrueType and OpenType

                            - collected files for Type 1 fonts have 0 byte size

                             

                            I tried it on a Mac (10.6) with ID CS6.

                             

                            May this be a general problem with (old) Type 1 fonts?

                            • 11. Re: Collect used fonts
                              Peter Kahrel Adobe Community Professional & MVP

                              That's not necessarily a problem with the scripts. What size are the fonts really on your disk?

                              • 12. Re: Collect used fonts
                                q3player Level 1

                                collect_type1_0byte_a.jpg

                                 

                                On disk it's 37 KB, after collecting with the script the copied file is 0 KB.

                                 

                                collect_type1_0byte_b.jpg

                                This is the preview of 37 KB file.

                                 

                                collect_type1_0byte_c.jpg

                                And the preview of 0 KB file.

                                 

                                I have found a script for collecting fonts with AI CS6 and there's the same result depending on the type of font: OpenType and TrueType work fine, Type 1 fonts are always 0 KB files. I use the Universal Type Server/Client, but to be sure for my tests I only used fonts that are installed local.

                                • 13. Re: Collect used fonts
                                  Peter Kahrel Adobe Community Professional & MVP

                                  I think it has something to do with the way Type 1 fonts are copied (handled in general, probably) on the Mac. I don't use a Mac myself so I can't say much about it other than when I've asked people to include their Type 1 fonts they were often 0 bytes.

                                   

                                  Let's see if someone who knows OS has an idea.

                                  • 14. Re: Collect used fonts
                                    q3player Level 1

                                    Thanks for your replies.

                                    Maybe there's a workaround - if possible - to access the parent directory of the font file and copy the complete folder instead of single files.

                                    • 15. Re: Collect used fonts
                                      Laubender Adobe Community Professional & MVP

                                      Hi,

                                      a workaround for your Type 1 fonts is to use InDesign's Packaging feature.

                                      I would test with your sample document if Packaging will duplicate the Type 1 font files.

                                      And if yes, if the file size is ok…

                                       

                                      Regards,
                                      Uwe

                                      • 16. Re: Collect used fonts
                                        q3player Level 1

                                        Good morning Uwe.

                                         

                                        <http://transfer.can-do-design.de/Diverses/typotest.zip>

                                         

                                        I've collected a simple AI CS6 file and the three fonts used in it.

                                         

                                        Regards,

                                        Markus

                                        • 17. Re: Collect used fonts
                                          Laubender Adobe Community Professional & MVP

                                          Hi Markus,

                                          thank you for providing the files.

                                          Did some tests.

                                           

                                          Document fonts folder is useless in this case. InDesign cannot see the Type-1 fonts there!

                                          The Type 1 fonts must be installed in InDesign's Fonts folder under Applications.

                                          Then the font is available: OS X 10.11.6 German with InDesign CC 2018.1 13.1.0.76.

                                           

                                          Regards,
                                          Uwe

                                          1 person found this helpful
                                          • 18. Re: Collect used fonts
                                            Laubender Adobe Community Professional & MVP

                                            A follow up on this:
                                            Used fonts can be packaged with InDesign on OS X 10.11.6.

                                            Strange enough, the fonts will be found and can be used with the packaged InDesign document.

                                            For this test—open the packaged document—I uninstalled the fonts from InDesign's Font folder in Applications and restarted the app.

                                             

                                            Maybe I have to redo my first test from my reply above without using subfolders in the Document fonts folder?

                                             

                                            Regards,
                                            Uwe

                                            1 person found this helpful
                                            • 19. Re: Collect used fonts
                                              Laubender Adobe Community Professional & MVP

                                              And yes, I can confirm that if I am using Peter's script in answer #7 here, that the file size of the collected Type-1 fonts is zero.

                                              So I would suggest ( again ) to us InDesign's Packaging feature to collect the used fonts.

                                               

                                              Regards,
                                              Uwe

                                              1 person found this helpful
                                              • 20. Re: Collect used fonts
                                                q3player Level 1

                                                Hello Uwe,

                                                 

                                                as we are (almost exclusively) working with Illustrator I would suggest to use InDesign for collecting the fonts to my colleagues. We are using the Extensis Universal Type Server/Client and ther's a plug-in for Illustrator to do the job. In fact this plug-in cannot be used for actions or any type of script (info provided by Extensis).

                                                 

                                                But thanks anyway, now I#m sure I've tested all possibilities.

                                                 

                                                Markus

                                                • 21. Re: Collect used fonts
                                                  Laubender Adobe Community Professional & MVP

                                                  Hi Markus,

                                                  collecting fonts with placed Illustrator files only—without using the fonts on actual InDesign text will not work.
                                                  InDesign's packaging feature is listing the fonts as embedded and will not collect them for packaging.

                                                  ( I just tested this with an InDesign document where I only placed your AI sample document.)

                                                   

                                                  Regards,
                                                  Uwe