• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Collect used fonts

Guide ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Jan 18, 2017 Jan 18, 2017

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.location);

  if(!cFile.exists) continue;

  cName = cFile.name;

  outFile = File(movefolder + "/"+ cName);

  cFile.copy(outFile);  

  }

Jarek

Votes

Translate

Translate
Community Expert ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

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

P.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

Thanks Peter, i will try as you adviced

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 17, 2017 Jan 17, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

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.location);

  if(!cFile.exists) continue;

  cName = cFile.name;

  outFile = File(movefolder + "/"+ cName);

  cFile.copy(outFile);  

  }

Jarek

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

Thank you Jarek.. It is working fine..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

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.location).name;

  File (myFonts.location).copy(File(movefolder+'/'+name));

}

P.

(Jarek beat me to it!)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

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..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 07, 2022 Oct 07, 2022

Copy link to clipboard

Copied

Hi... I'm trying an approach to this on Illustrator 2022, but with no success.
It seems we don't have fonts inside the document model anymore.

There is a way to make it work in newer versions?

WilsonFaustino_0-1665179558713.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 07, 2022 Oct 07, 2022

Copy link to clipboard

Copied

LATEST

LOL.. seems I need to learn to read the complete post before post a reply.. 
Sorry, guys. 

I'll try to find what I need on the correct forum for Illustrator.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines