Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

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

Explorer ,
Jul 06, 2023 Jul 06, 2023

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!

TOPICS
Scripting , Type
447
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 06, 2023 Jul 06, 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 do
...
Translate
Community Expert ,
Jul 06, 2023 Jul 06, 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2023 Jul 06, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2023 Jul 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 07, 2023 Jul 07, 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2023 Jul 07, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 08, 2023 Jul 08, 2023
LATEST

You're the best! Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2023 Jul 07, 2023

Thanks Mark, I missed the textBoxes property in formFields.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines