These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Change font color in entire form using script

reuistdabei
Registered: Mar 15 2010
Posts: 6
Answered

I hope someone can help me with this:

I can change the font of text boxes and the "cross" in check boxes to red and bold with the following script. I entered the script for each text box/check box:

this.fontColor = "255,0,0"
this.font.weight = "bold";

Is there a way to apply this script to an enitre form, so that the font in all the text boxes and check boxes is changed?

Many thanks for suggestions.
Kind regards,
Ueli

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, you can write a loop that walks through all fields on the form.
 // Iterate over all the pagesfor (var pageIndex = 0; pageIndex < numberOfPages; pageIndex++) {formObjects = xfa.layout.pageContent(pageIndex, "field")numberOfFormObjects = formObjects.length // Iterate all the interactive objects retrieved from the pagefor (var formObjectIndex = 0; formObjectIndex < numberOfFormObjects; formObjectIndex++) {formObject = formObjects.item(formObjectIndex) formObject.fontColor = "255,0,0";formObject.font.weight = "bold"; }}

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

reuistdabei
Registered: Mar 15 2010
Posts: 6
Many thanks for your answer and your effort. Unfortunately, I did not work with my form.
I put the script under "form:ready" for the topmost subform.

topmostSubform.#pageSet[0].PageArea1.CurrentPage::ready:form - (JavaScript, client)

Maybe, that's not correct.
Do you have any hint why it was not working?

Your answer is very much appreciated.

Kind regards,
reuistdabei
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There could very easily be an error in the code. Look in the console window and see what's reported when the form is opened.

BTW: don't test the form by opening it in the preview window. Start up a separate instance of Acrobat and open your form in that.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

reuistdabei
Registered: Mar 15 2010
Posts: 6
The error reported is as follows:

Script failed (language is javascript; context is xfa[0].form[0].topmostSubform[0])
script=

for (var pageIndex = 0; pageIndex < numberOfPages; pageIndex++) {
formObjects = xfa.layout.pageContent(pageIndex, "field")
numberOfFormObjects = formObjects.length


for (var formObjectIndex = 0; formObjectIndex < numberOfFormObjects; formObjectIndex++) {
formObject = formObjects.item(formObjectIndex)

formObject.fontColor = "255,0,0";
formObject.font.weight = "bold";

}
}


Error: numberOfPages is undefined


Kind regards,
Ueli
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well there you go, add this code to the top of the script.

var numberOfPages = xfa.layout.pageCount();

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script