Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

How to change master page subform background colour


Level 2

I have a form with two master pages. On each master page there are two subforms with header and footer content.

When the form is printed, I want to change the background colour of the subforms, from grey to white. This will reduce toner useage.

I have put script into the preprint and postprint events but whilst the script seems to be executed, the colour does not change.

Is there something different about the object model that I need to take into account?

This is the script that I have on the form for each subform affected.

<event activity="prePrint" ref="$host" name="event__prePrint">

     <script contentType="application/x-javascript">

          this.border.fill.color.value = globalWhiteColour.value;



<event activity="postPrint" ref="$host" name="event__postPrint">

     <script contentType="application/x-javascript">

          this.border.fill.color.value = globalHdrBackgroundColour.value;



When I put debugging script in the events I could verify that the colour settings were indeed changed, just that when printed, the colour had not.

Any suggestions appreciated.

0 Replies


Level 10

I tried something more direct, putting script into Print Button click event. The object model for subforms requires "fillColor" although the XML source behind the subform suggests your code should work.

// form1.page2.printBtn::click - (JavaScript, client)

form1.page1.subform1.fillColor = "255,255,255";

form1.page1.subform2.fillColor = "255,255,255";

form1.page2.subform1.fillColor = "255,255,255";

form1.page2.subform2.fillColor = "255,255,255";, "0", ( -1).toString(), 0, 0, 0, 0, 0);



Level 2

I have tried this and it does not work in my real form.

Debugging javascript print statements in the button click event show that the colour is changed in the code, but the displayed form still does not change colour.

I made a dummy example on a new document to test it and that did work correctly, even when putting the fillColor change in the prePrint event of the subform on the master page.

So it is something about how my form (two master pages, lots of subforms, lots of script)  is built that is preventing the code executing properly.

Where and why that might be I just don't know.

Back to the drawing board.

Thanks for the suggestions though.



Level 10


Make sure that the form is saved as a Dynamic XML Form in the save-as dialog.

Another option would be to use the presence method to hide the fill before printing, eg in prePrint:

this.border.fill.presence = "invisible";

And postPrint:

this.border.fill.presence = "visible";

Another option would be to have a light grey rectangle over the whole page and set its presence in the Objet > Field palette to "Visible (screen only)".

Hope that helps,



Level 2

Got all excited that it might work..... but it didn't.

I did fiddle with the Master page though as there is a background rectangle on it to colour the body of the page.

I resized it so that it fits between the header and footer sections.

I'm going to see if I can hide the whole hdr and ftr sections. - nope no effect at all.

Does it make any difference if there are multiple pages in the printed doc?

Should I be iterating through the pages to access each page's hdr and ftr?

It appears to me that I cannot change anything about a Master page dynamically at all.


Level 10


Not sure what is going on. Just checked one of our multi-page forms with multiplt Master Pages. I sometimes use an off-white rectangle (250,250,250) on each Master Page. The settings work without the need for scripting:

If your script is in an object on the Master Page then relative references should work. However if your script is in an object on the Design Pages and you are referencing objects on the Master Page in the script, then you will need to resolve the node. For example:

xfa.resolveNode("#pageSet.Page1.Rectangle").border.fill.presence = "invisible";

Hope that helps,



Level 2

Ok that clue definitely helped.

I changed the form so that the MasterPage subform has a white background.

Removed any script in the pre- and post-print events for the subforms relating to colour settings

Added a rectangle inside the subform with coloured background, layout sent to back, and set the Presence to screen only.

Voila, that worked. I now have grey background whilst viewing on screen,and white when printing.

A simple solution though not at all obvious.

Lesson learned - no point in trying to change Master page elements in pre and post print events.

(Though my error may be in the object references somewhere.......)

Thanks for everyone's help.