Hi,
Thanks for your reply.
I have created a document with pagecolor as black, so the default text color automatically appeared as white in MSWord.
Process1: Getting the pageColor
Document doc = new Document("backcolor_black.docx");
Color color = doc.getDocument().getPageColor();
String backColor = "rgb(" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ")";
System.out.println("page Color = " + backColor);
Result:
backColor = rgb(0,0,0)
Process2: Setting the pageColor to a new Document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getDocument().getDocument().setPageColor(getColor(backColor));
doc.save("Color.doc", SaveFormat.DOC);
public static Color getColor(String style)
{
try
{
if (style.contains("rgb"))
{
String color = style.replace("rgb", "");
color = color.replace(')', '');
color = color.replace('(', '');
color = color.trim(); int red = Integer.parseInt(color.substring(0, color.indexOf(","))); System.out.println("Red = " + red); color = color.substring(color.indexOf(",") + 1); int green = Integer.parseInt(color.substring(0, color.indexOf(","))); color = color.substring(color.indexOf(",") + 1); int blue = Integer.parseInt(color); System.out.println(new Color(red, green, blue));
return new Color(red, green, blue);
}
else
{
style = style.replace('#', '').trim();
int intValue = Integer.parseInt(style, 16);
return new Color(intValue);
}
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Exception in setStyleforRun:::::", e);
}
return null;
}
I couldn’t get the same pagecolor in the newly created document(Color.doc).Please correct my code if there is anything wrong.