Skip to main content
tpk1982
Legend
January 17, 2017
Answered

Collect used fonts

  • January 17, 2017
  • 1 reply
  • 3105 views

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

This topic has been closed for replies.
Correct answer Jump_Over

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


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

1 reply

Peter Kahrel
Community Expert
Community Expert
January 17, 2017

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

P.

tpk1982
tpk1982Author
Legend
January 17, 2017

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

Peter Kahrel
Community Expert
Community Expert
January 18, 2017

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


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!)