Copy link to clipboard
Copied
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!
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...
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Hi @dpajewski, I have updated my posted script with an extra line which collects TextBoxes from tables. - Mark
Copy link to clipboard
Copied
You're the best! Thank you!
Copy link to clipboard
Copied
Thanks Mark, I missed the textBoxes property in formFields.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now