Skip to main content
Inspiring
July 6, 2023
Answered

Find/Replace a font that is applied to an interactive text field

  • July 6, 2023
  • 3 replies
  • 451 views

Hi, I've searched to no avail...I have document with many inline text fields, some inside of tables, for users to add notes when it's exported to an interactive PDF. Somehow, some of the properties of the text field were changed to a different font. Is there a way (or a script) to find and replace a font that's applied to a text field?

Thanks!

This topic has been closed for replies.
Correct answer m1b

Hi @dpajewski, if you have set up the form fields as TextBoxes, similar to my attached demo document, then try the following script—it will set the font, style and size of every TextBox. (Note: TextBoxes are interactive objects, distinct from TextFrames.)

- Mark

 

/**
 * Set font of form field text boxes.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/find-replace-a-font-that-is-applied-to-an-interactive-text-field/m-p/13918197
 */
function main() {

    var doc = app.activeDocument,
        textBoxes = doc.textBoxes.everyItem().getElements();

    // also add any anchored textBoxes
    textBoxes = textBoxes.concat(doc.stories.everyItem().textBoxes.everyItem().getElements());
    // also add any textBoxes in tables
    textBoxes = textBoxes.concat(doc.stories.everyItem().tables.everyItem().cells.everyItem().textBoxes.everyItem().getElements());

    // for each textBox, set the font etc.
    for (var i = 0; i < textBoxes.length; i++) {

        textBoxes[i].properties = {
            appliedFont: 'Minion Pro',
            fontStyle: 'Regular',
            fontSize: 12,
        };

    }

}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Set Form Text Box Font");

 

Edit 2023-07-08: Now collects TextBoxes from tables.

3 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
July 7, 2023

Hi @dpajewski, if you have set up the form fields as TextBoxes, similar to my attached demo document, then try the following script—it will set the font, style and size of every TextBox. (Note: TextBoxes are interactive objects, distinct from TextFrames.)

- Mark

 

/**
 * Set font of form field text boxes.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/find-replace-a-font-that-is-applied-to-an-interactive-text-field/m-p/13918197
 */
function main() {

    var doc = app.activeDocument,
        textBoxes = doc.textBoxes.everyItem().getElements();

    // also add any anchored textBoxes
    textBoxes = textBoxes.concat(doc.stories.everyItem().textBoxes.everyItem().getElements());
    // also add any textBoxes in tables
    textBoxes = textBoxes.concat(doc.stories.everyItem().tables.everyItem().cells.everyItem().textBoxes.everyItem().getElements());

    // for each textBox, set the font etc.
    for (var i = 0; i < textBoxes.length; i++) {

        textBoxes[i].properties = {
            appliedFont: 'Minion Pro',
            fontStyle: 'Regular',
            fontSize: 12,
        };

    }

}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Set Form Text Box Font");

 

Edit 2023-07-08: Now collects TextBoxes from tables.

dpajewskiAuthor
Inspiring
July 7, 2023
quote

Hi @dpajewski, if you have set up the form fields as TextBoxes, similar to my attached demo document, then try the following script—it will set the font, style and size of every TextBox. (Note: TextBoxes are interactive objects, distinct from TextFrames.)

- Mark

 

/**
 * Set font of form field text boxes.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/find-replace-a-font-that-is-applied-to-an-interactive-text-field/m-p/13918197
 */
function main() {

    var doc = app.activeDocument,
        textBoxes = doc.textBoxes.everyItem().getElements();

    // also add any anchored textBoxes
    textBoxes = textBoxes.concat(doc.stories.everyItem().textBoxes.everyItem().getElements());

    // for each textBox, set the font etc.
    for (var i = 0; i < textBoxes.length; i++) {

        textBoxes[i].properties = {
            appliedFont: 'Minion Pro',
            fontStyle: 'Regular',
            fontSize: 14,
        };

    }

}

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Set Form Text Box Font");

 

 


By @m1b

 

Thank you so much! I couldn't open your demo file since you have a newer version of IND, however I ran the script in my file and it worked! The only thing it didn't touch were the text fields that were in a table. But there's not a lot of those so I can manually change them. 

Thanks again for your help, this saves me so much time!

m1b
Community Expert
Community Expert
July 7, 2023

Hi @dpajewski, I have updated my posted script with an extra line which collects TextBoxes from tables. - Mark

rob day
Community Expert
Community Expert
July 6, 2023

Hi @dpajewski , If by text field you mean a buttons and forms text field, then probably not via the InDesign scripting API.

 

An InDesign document can have a collection of formField objects, but the formField object does not have a font property:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html

 

Might be possible via the Acrobat API, maybe ask in the Acrobat forum

John Mensinger
Community Expert
Community Expert
July 6, 2023

Targeting with a script sounds doable, but I'm no scripter.

 

Type > Find/Replace Font works on text field font assignments. The only thing is, if that same font is used in non-field text frames, the only way to find/change selectively is step through the document, one instance at a time (as opposed to just clicking Change All).