Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

how to give some part of text a different color then the remaining text?


Level 1


*First Name - * should be red and remaining text black. Also, these both should be a single text field and not two separate text fields.

This is in Adobe Forms (LiveCycle Designer).

3 Replies


Level 10

There is a function which you can use to do this.


Here is an example for bold value, you can use the same for different colors but you gotta change the style, it is most likely CSS language:  style=\"font-weight:bold;color:red;letter-spacing:0in\"

If you get and error "exData" is not valid or doesn't exist, to fix it you must already have a special style inside the text when you render the PDF...

What I usually do is just have blank space to be bold or colour changed, there might be some other way to have "exData", but that's the easiest way I found yet.


Level 10


Just a slight alternative you can also build up the rich text using the Span objects, http://livedocs.adobe.com/acrobat_sdk/11/Acrobat11_HTMLHelp/JS_API_AcroJS.89.1168.html

So something like;


var spans = [];

spans.push({text:"Roberto Sobrino"});

spans.push({text:"Some information about Roberto", textColor:color.red, fontWeight:700});

this.value.exData.loadXML(util.spansToXML(spans), false, true);


There is a lot of functionality that is not supported with this approach so sometimes specifying the XML directly is the only way but colors and bold are.  Also I don't think you can specify color names in the XML approach so you would need either the 6 digit hex string (like below) or the decimal numbers;

<exData contentType="text/html" xmlns="http://www.xfa.org/schema/xfa-template/3.6/">

   <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p style="font-family:'Myriad Pro';color:#ff0000;font-weight:bold">Roberto Sobrino<span style="xfa-spacerun:yes"> </span><span style="color:#000000;font-weight:normal;text-decoration:none">Some information about Roberto</span></p></body>





Level 1

Thanks a lot Magus069 and Bruce BR001 for your quick reply!

I will try these.