Skip to main content
Known Participant
September 27, 2010
Answered

Report on fonts from batch of documents

  • September 27, 2010
  • 4 replies
  • 4873 views

Hi, does anyone know if there is a script that can go through a folder of a thousand indesign files and create a report (with two choices) of what fonts are used. Choice 1: Just a list of fonts have been used without repeating what fonts have been used... so if "Times Roman" has been used on 30 indesign files the report only mentions "Times Roman once. Choice 2: A list of file names and what fonts are used in each file.

Cheers, Tim

This topic has been closed for replies.
Correct answer tomaxxi

Hey thanks for that. But would it be asking too much if there could be two adjustments:-)?

1. If the script could ignore any error messages such as missing links etc when going through the documents.

2. If the reports for the individual files could be collated into one document.

Many thanks, Tim


Ok, no big changes

Here is your script:

Array.prototype.unique = function (){var i, a = {},r = [],n = this.length;for( i=0 ; i<n ; ++i ) a[this]=1;for( i in a ) r.push(i);return r;}

if(app.documents.length == 0){
    fontReporter();
}else{
    alert("Please close all documents!","Font Report Creator");
}

function fontReporter(){
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
// write report to file
var writeReport = function(myData, myFile){myFile.open ('w'); myFile.encoding = 'UTF-8'; for(var d = 0; d < myData.length; d++)myFile.write (myData); myFile.close (); }
// collect info from document
var createFontReport = function(){
    var myDoc = app.documents[0];
    var myDocFonts = myDoc.fonts;
    var myDocName = myDoc.name;
    myFonts.push("//// Font report for file: [ " + myDocName + " ] ////\r\r");
    for(var f = 0; f < myDocFonts.length; f++){var myString = myDocFonts.fontFamily + "\t" + myDocFonts.fontStyleName + "\t" + myDocFonts.location + "\r"; myFonts.push(myString); myFontsAll.push(myString);}
    //myFonts.sort();
    myFonts.push("\r//// Fonts used count: " + f + " ////\r\r\r");

}

    var myFonts = [];
    var myFontsAll = [];

    // open/report/close
    var myFolder = Folder.selectDialog("Please select a folder containing the InDesign files.");
    if(myFolder == null){alert("No folder selected!","Font Report Creator"); exit();}

    var myFolderContents = myFolder.getFiles("*.indd");
    if(myFolderContents.lenght == 0){alert("No InDesign files in folder!","Font Report Creator"); exit();}

    for (var i = 0; i < myFolderContents.length; i++) {
        app.open(File(myFolderContents), false);
        if(app.documents[0].saved == true)createFontReport();
        app.documents[0].close(SaveOptions.no);
    }

    var myReportFile = File(myFolder + "/" + "Separate document report - Font Report.txt");
    writeReport(myFonts, myReportFile);

    // complete report
    myFontsAll = myFontsAll.unique();
    myFontsAll.sort();
    myFontsAll.unshift("//// Font report for folder: [ " + myFolder + " ]////\r\r");
    myFontsAll.push("\r//// Fonts used count: " + (myFontsAll.length - 1) + " ////");
    myReportFile = File(myFolder + "/All [INDD] Documents Font Report.txt");
    writeReport(myFontsAll, myReportFile);

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

alert("Font reports created!","Font Report Creator");
}

--

tomaxxi

http://indisnip.wordpress.com/

4 replies

Participating Frequently
April 23, 2024

Been trying to get this script to run, continues to get an error. Any and all help would be greatly appericated. 

Community Expert
April 23, 2024

Change the line 

app.open(File(myFolderContents), false);

To

app.open(File(myFolderContents[i]), false);

-Manan

-Manan
Community Expert
April 24, 2024

On further checking the code I see there are other areas as well which seems to have corrupted due to forum migration. The following code should work

Array.prototype.unique = function () { var i, a = {}, r = [], n = this.length; for (i = 0; i < n; ++i) a[this] = 1; for (i in a) r.push(i); return r; }
if (app.documents.length == 0) {
    fontReporter();
} else {
    alert("Please close all documents!", "Font Report Creator");
}

function fontReporter() {
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
    // write report to file
    var writeReport = function (myData, myFile) { myFile.open('w'); myFile.encoding = 'UTF-8'; for (var d = 0; d < myData.length; d++)myFile.write(myData); myFile.close(); }
    // collect info from document
    var createFontReport = function () {
        var myDoc = app.documents[0];
        var myDocFonts = myDoc.fonts;
        var myDocName = myDoc.name;
        myFonts.push("//// Font report for file: [ " + myDocName + " ] ////\r\r");
        for (var f = 0; f < myDocFonts.length; f++){
            var myString = myDocFonts[f].fontFamily + "\t" + myDocFonts[f].fontStyleName + "\t" + myDocFonts[f].location + "\r";
            myFonts.push(myString); myFontsAll.push(myString);
        }
        //myFonts.sort();
        myFonts.push("\r//// Fonts used count: " + f + " ////\r\r\r");
    }
    var myFonts = [];
    var myFontsAll = [];
    // open/report/close
    var myFolder = Folder.selectDialog("Please select a folder containing the InDesign files.");
    if (myFolder == null) { alert("No folder selected!", "Font Report Creator"); exit(); }
    var myFolderContents = myFolder.getFiles("*.indd");
    if (myFolderContents.lenght == 0) { alert("No InDesign files in folder!", "Font Report Creator"); exit(); }
    for (var i = 0; i < myFolderContents.length; i++) {
        app.open(File(myFolderContents[i]), false);
        if (app.documents[0].saved == true) createFontReport();
        app.documents[0].close(SaveOptions.no);
    }
    var myReportFile = File(myFolder + "/" + "Separate document report - Font Report.txt");
    writeReport(myFonts, myReportFile);
    // complete report
    myFontsAll = myFontsAll.unique();
    myFontsAll.sort();
    myFontsAll.unshift("//// Font report for folder: [ " + myFolder + " ]////\r\r");
    myFontsAll.push("\r//// Fonts used count: " + (myFontsAll.length - 1) + " ////");
    myReportFile = File(myFolder + "/All [INDD] Documents Font Report.txt");
    writeReport(myFontsAll, myReportFile);
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
    alert("Font reports created!", "Font Report Creator");
}

-Manan

-Manan
Participating Frequently
February 24, 2023

Wow this script is great!  Is there a way to modify it to also list the font sizes used for each font?

example:  Arial Bold 32pt, Arial Regular 16pt, etc.

 

Participant
September 14, 2020

Does anyone have a working link for 'FontReporter 2' ?
I'm after doing a similar report for 1,000's of InDesign CC documents.

Many thanks

Participant
September 28, 2020

Following. Haven't been able to find a working link anywhere. This would be really useful.

 

tomaxxi
Inspiring
September 27, 2010

Hey!

Well, it can be done really easily. You have to loop through all documents in folder, and for each to read app.activeDocument.fonts. I'll try to write something for you if you need help.

--

tomaxxi

http://indisnip.wordpress.com/

talltim1Author
Known Participant
September 27, 2010

Cheers, that would be great, much appreciated, I'm not a script writer but know how useful they can be!

Thanks, Tim

tomaxxi
Inspiring
September 27, 2010

Hey Tim!

This works with hidden documents to gain more speed, so you have to close all documents before executing.

Here you go:

Array.prototype.unique = function (){var i, a = {},r = [],n = this.length;for( i=0 ; i<n ; ++i ) a[this]=1;for( i in a ) r.push(i);return r;}

if(app.documents.length == 0){
    fontReporter();
}else{
    alert("Please close all documents!","Font Report Creator");
}

function fontReporter(){
// write report to file
var writeReport = function(myData, myFile){myFile.open ('w'); myFile.encoding = 'UTF-8'; for(var d = 0; d < myData.length; d++)myFile.write (myData); myFile.close (); }
// collect info from document
var createFontReport = function(){
    var myDoc = app.documents[0];
    var myDocFonts = myDoc.fonts;
    var myDocName = myDoc.name;
    var myReportFile = File(app.documents[0].fullName.path + "/" + myDocName + " - Font Report.txt");
    var myFonts = [];
    myFonts.push("//// Font report for file: [ " + myDocName + " ] ////\r\r");
    for(var f = 0; f < myDocFonts.length; f++){var myString = myDocFonts.fontFamily + "\t" + myDocFonts.fontStyleName + "\t" + myDocFonts.location + "\r"; myFonts.push(myString); myFontsAll.push(myString);}
    myFonts.sort();
    myFonts.push("\rFonts used count: " + f + " ////");
    writeReport(myFonts, myReportFile);
}

    var myFontsAll = [];

    // open/report/close
    var myFolder = Folder.selectDialog("Please select a folder containing the InDesign files.");
    if(myFolder == null){alert("No folder selected!","Font Report Creator"); exit();}

    var myFolderContents = myFolder.getFiles("*.indd");
    if(myFolderContents.lenght == 0){alert("No InDesign files in folder!","Font Report Creator"); exit();}

    for (var i = 0; i < myFolderContents.length; i++) {
        app.open(File(myFolderContents), false);
        if(app.documents[0].saved == true)createFontReport();
        app.documents[0].close(SaveOptions.no);
    }

    // complete report
    myFontsAll = myFontsAll.unique();
    myFontsAll.sort();
    myFontsAll.unshift("//// Font report for folder: [ " + myFolder + " ]////\r\r");
    myFontsAll.push("\r//// Fonts used count: " + (myFontsAll.length - 1) + " ////");
    var myReportFile = File(myFolder + "/All [INDD] Documents Font Report.txt");
    writeReport(myFontsAll, myReportFile);

alert("Font reports created!","Font Report Creator");
}

Hope it helps!

--

tomaxxi

http://indisnip.wordpress.com/