Copy link to clipboard
Copied
Error in this line: var fontName = textFrames[i].textRange.characterAttributes.textFont.name;
Here is the code:
var textFrames = app.activeDocument.textFrames;
// Create an object to store
var usedFonts = {};
// Loop through all text frames
for (var i = 0; i < textFrames.length; i++) {
var fontName = textFrames[i].textRange.characterAttributes.textFont.name;
if (!usedFonts[fontName]) {
usedFonts[fontName] = true;
}
}
for (var font in usedFonts) {
$.writeln(font);
}
Hi @virender_CTS , A textFrame has no textRange property—try textStyleRanges:
//gets the fons used in the document’s first text frame
var tr = app.activeDocument.textFrames[0].textStyleRanges;
for (var i = 0; i < tr.length; i++){
$.writeln(tr[i].appliedFont.name)
};
Copy link to clipboard
Copied
Hi @virender_CTS , A textFrame has no textRange property—try textStyleRanges:
//gets the fons used in the document’s first text frame
var tr = app.activeDocument.textFrames[0].textStyleRanges;
for (var i = 0; i < tr.length; i++){
$.writeln(tr[i].appliedFont.name)
};
Copy link to clipboard
Copied
In addition to Rob's suggestion, you can also use this:
$.writeln (app.activeDocument.fonts.everyItem().name.join('\r'));
An advantage of this approach is that every font name is returned just once.
Note that in both Rob's and my approach you get only the fonts that are used in text. Fonts in unused character and paragraph styles aren't reported.
P.
Copy link to clipboard
Copied
Thank you Peter.