We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to set text shading and text highlight using Java

Dear Team ,

I am using Aspose latest version for document conversion .I have attached document with this post which has text with highlight color . I am using ’ getHighlightColor()’ to get highlight color, but i am not getting the applied color for this doc. Can you tell us what the problem is ? .

Thanks,
Anbu.

Hi Anbu,

Thanks for your query. Please use the following code snippet to get the highlight text color and shading foreground color of each Run. The document you shared has not highlighted text color, You applied shading color to text. Please read Highlight or shade text with color.

Document doc = new Document(DirDoc + "TextHighlight.docx");

Node[] paras = doc.getChildNodes(NodeType.PARAGRAPH, true).toArray();

for(int i=0; i < paras.length; i ++)

{

Node[] runs = ((Paragraph)paras[i]).getChildNodes(NodeType.RUN, true).toArray();

for(int j=0; j < runs.length; j ++)

{

//Shading color

Color Shadingcolor = ((Run)runs[j]).getFont().getShading().getForegroundPatternColor();

System.out.println(Shadingcolor);

//Highlight text color

Color HighlightColor = ((Run)runs[j]).getFont().getHighlightColor();

System.out.println(HighlightColor);

}

}