Skip to main content
wolfeEdition
Known Participant
August 11, 2017
Question

Batch Processing a Find Font in Document

  • August 11, 2017
  • 3 replies
  • 1867 views

I am wanting to have a script that will look in a folder/directory and...

- Open each .pdf file in that directory one at a time and do the following

     - Find Font in Document

          - Arial

     - Replace With Font From System

          - Courier New

- Save the file with default Illustrator PDF save settings in same location (in other words I don't need it to be saved as another file)

I would love to do this with minimal or no interaction from the user.

Any ideas if this is possible? Keeping in mind that each file will have 1,000's of text frames with the Arial font that need to be changed to Courier New.

Any help would be greatly appreciated!

This topic has been closed for replies.

3 replies

wolfeEdition
Known Participant
August 25, 2017

Here is the code I am working with.... can anyone offer any suggestions/help?

#target illustrator

var arialText = app.textFonts.getByName("ArialMT")

var arialBold = app.textFonts.getByName("Arial-BoldMT")

//Set up vairaibles

var sourceDoc, sourceFolder;

var count = 0;

// Select the source folder.

sourceFolder = Folder.selectDialog('Select the folder with Illustrator files...', '~');

destDoc = app.documents.add();

// If a valid folder is selected

if (sourceFolder != null) {

    files = new Array();

    // Get all files matching the pattern

    files = sourceFolder.getFiles();

    if (files.length > 0) {

        // Get the destination to save the files

        for (xx = 0; xx < files.length; xx++) {

sourceDoc = app.open(files[xx]); // returns the document object

            var allText = sourceDoc.textFrames; // Select All layers in Active Document

for (i = 0; i < allText.length; i++) {

var textFieldRange = allText.textRange;

var textProps = textFieldRange.characterAttributes;

var textFrameFont = textProps.textFont;

if (textFrameFont == "[TextFont ArialMT]" || textFrameFont == "[TextFont Arial-BoldMT]" || textFrameFont == "[TextFont Arial-BoldItalicMT]" || textFrameFont == "[TextFont Arial-ItalicMT]" || textFrameFont == "[TextFont ArialNarrow]" || textFrameFont == "[TextFont Arial-Black]"){

// font is correct

}

else if (textFrameFont == "[TextFont MonospaceBT]"){

// change the font to ArialMT which is Arial Regular

textFieldRange.characterAttributes.textFont = arialText;

count++

}

else{

// change the font to Arial Bold

textFieldRange.characterAttributes.textFont = arialBold;

count++;

}

}

sourceDoc.close(SaveOptions.SAVECHANGES);

}

}

}

// Alerts based on count

if (count == 0){

alert("YOU'RE GOOD TO GO!\nAll text in this document are a form of Arial!");

}

else {

alert("Complete!\n" + count + " textFrames were not a form of Arial.");

}

Stephen Marsh
Community Expert
Community Expert
August 15, 2017

Are the PDF files created in Illustrator with “preserve Illustrator editing capabilities” checked when saving? If not, opening a generic PDF into Illustrator may be problematic (Illustrator is not a general purpose PDF editor).

Prepression: The Ten Commandments of PDF

I would recommend Enfocus PitStop Pro for Adobe Acrobat Pro or the stand alone hot folder based Enfocus PitStop Server for this task.

EDIT: Do you have some random sample files? Depending on how the text is composed, changing the font (in any software) could lead to unexpected results…

Ten A
Community Expert
Community Expert
August 11, 2017

If you familiar to JavaScript, You can use ExtendScript do that.

wolfeEdition
Known Participant
August 15, 2017

I am familiar with JavaScript and ExtendScript....but this is beyond my abilities.

Silly-V
Legend
August 15, 2017

I'm not sure how to do this in AI, because I don't think there's any way to replicate the function of the Find Font dialog. Going through all the 1000s of text frames to check each character's font family name would most certainly be too slow on even a single file.

How can one accomplish this?