Taking PageColor and Text backColor

Hi,

I am using Aspose Words for java 10.2 for my conversion. I created a document with backColor as violet. How to take the default document text backColor(which is now violet).

Note:Document Attached.

Hi
Thanks for your request. You can set background color of paragraphs. Please see the following code:

Document doc = new Document();
DocumentBuilder builder =new DocumentBuilder(doc);
// Set document bg color.
doc.PageColor = Color.Violet;
// Set background color of paragraphs.
builder.ParagraphFormat.Shading.BackgroundPatternColor = Color.DeepPink;
// Set color of text.
builder.Font.Color = Color.DarkGreen;
// Insert some text.
builder.Write("Hello World!!!");
doc.Save(@"Test001\out.doc");

Hope this helps.
Best regards,

Thanks for your reply. How to take a default document backcolor and foregroundColor for paragraph and text.

Hi
Thanks for your request. You can get default document backcolor and foreground color using the following code:

Console.WriteLine(doc.Styles["Normal"].Font.Color);
Console.WriteLine(doc.Styles["Normal"].ParagraphFormat.Shading.BackgroundPatternColor);
Console.WriteLine(doc.Styles["Normal"].ParagraphFormat.Shading.ForegroundPatternColor);

Best regards,

Hi,

Thanks for your reply. please provide me sample java code. I have used the following code for the above attached document.

System.out.println("Page Color = "+doc.getPageColor());
System.out.println("Text backcolor = "+doc.getStyles().getByStyleIdentifier(StyleIdentifier.NORMAL).getFont().getShading().getBackgroundPatternColor());
System.out.println("Paragraph backcolor = "+doc.getStyles().getByStyleIdentifier(StyleIdentifier.NORMAL).getParagraphFormat().getShading().getBackgroundPatternColor());

I am getting pagecolor as [r=178,g=161,b=199], but the text and paragraph backcolor as [r=0,g=0,b=0](which is black). I want text backcolor as same as pagecolor(How to take it).Please clarify me if i somewhere wrong.

Hi
Thanks for your request. I think, the problem occurs because you are ignoring alpha component of the color. I corrected your code. Please see the code below:

Document doc = new Document("C:\\Temp\\in.docx");
Color color = doc.getDocument().getPageColor();
String backColor ="rgb("+color.getRed()+","+color.getGreen()+","+color.getBlue()+","+color.getAlpha()+")";
System.out.println("Page Color = "+backColor );
color = doc.getStyles().getByStyleIdentifier(StyleIdentifier.NORMAL).getFont().getShading().getBackgroundPatternColor();
String textBackcolor = "rgb("+color.getRed()+","+color.getGreen()+","+color.getBlue()+","+color.getAlpha()+")";
System.out.println("Text backcolor = " + textBackcolor);
color = doc.getStyles().getByStyleIdentifier(StyleIdentifier.NORMAL).getParagraphFormat().getShading().getBackgroundPatternColor();
String paragraphBackcolor = "rgb("+color.getRed()+","+color.getGreen()+","+color.getBlue()+","+color.getAlpha()+")";
System.out.println("Paragraph backcolor = "+paragraphBackcolor);

You will get r=0, g=0, b=0, a=0 it is transparent.
Best regards,