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

Free Support Forum - aspose.com

Issue in ForegroundPatternColor

I am using following code


DocumentBuilder.r.getCellFormat().getShading().setForegroundPatternColor()

This is not working.
Where as

DocumentBuilder.getCellFormat().getShading().setBackgroundPatternColor()

This works properly.

So it is limitation or known bug that setForegroundPatternColor will not work?
I am using Aspose Words 10.2.0.0

Hi Amey,


Thanks for your inquiry. First, I would suggest you please upgrade to the latest version of Aspose.Words i.e. 13.4.0. You can download it from the following link:
http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/default.aspx

Secondly, to test your scenario, please try run the following code snippet:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Set paragraph borders
BorderCollection borders = builder.getParagraphFormat().getBorders();
borders.setDistanceFromText(20);
borders.setLineStyle(LineStyle.DOUBLE);

// Set paragraph shading
Shading shading = builder.getParagraphFormat().getShading();
shading.setTexture(TextureIndex.TEXTURE_DIAGONAL_CROSS);
shading.setBackgroundPatternColor(Color.WHITE);
shading.setForegroundPatternColor(Color.BLACK);

builder.write(“I’m a formatted paragraph with double border and nice shading.”);

doc.save(“C:\Temp\out.docx”);

I hope, this helps.

Best regards,
H Awais,
Thanks for your response.
I can not upgrade to latest version since i have license cost issues.
1:So can you confirm me if this is bug in older version & which have been fixed in 13.4.0?
2:Example which you have specified is adding ForegroundPattern in ParagraphFormat's shadings object where as i want it for cell.
3:Is it something like that we can not use same for cellformat or it is bug & any workaround for same available?
4:setBackgroundPatternColor perfectly works in cellformat's shading just setForegroundPatternColor is not working.

Hi Amey,


Thanks for the additional information and sorry for the confusion. Please use the following code instead to be able to specify the color that’s applied to the foreground of the Shading object.
Cell firstCell = table.getFirstRow().getFirstCell();
firstCell.getCellFormat().getShading().setTexture(TextureIndex.TEXTURE_DIAGONAL_CROSS);
firstCell.getCellFormat().getShading().setForegroundPatternColor(Color.GREEN);
I hope, this helps.

Best regards,