Free Support Forum - aspose.com

Converting into html: problem with auto color

Dear Apose Team,

I currently have a problem with a specific table formatting. The table seems to have black background in some cells with white Font. But the font is autocolor and - strange thing - the cell background is also autocolor. It seems, that there is a special property for cell shading. The cells have their shading-style set to solid 100% with autocolor. This seems to lead to black cell color.

I use a programmatic workaround to determine the background color for each text which has autoColor, to set the color manually on conversions. In this special case i see no chance to get the style of the cell by the Aspose API. So my workaround just dont work in this specific case and the font in the table cells is also converted into black.

Note: When converting into png, the font color is converted correctly somehow. Only when converting into html, it does not apply.

The used code is in general a bit more complex, but this code below should be enough to reproduce the problem (hopefully).

Code to reproduce the problem:

Document testDoc = new Document(badTableDocPath);

testdoc.Save(actualHtmlDocPath,SaveFormat.Mhtml);

I appreciate any suggestion of you, how I could work around this problem. Since this is a part from documents of our customers, I unfortunately have no chance to refactor the document itself.

Please find attached the document with the problematic table.

Kind regards, Wolfgang

Hi

Thank you for reporting this problem to us. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

It seems the problem occurs because background color is defined in table style. As a temporary workaround, you can try using code like the following:

Document doc = new Document(@"Test001\in.docx");

// Save/open the docuemnt in the format that does nto support table styles.

// In out case RTF.

using (MemoryStream ms = new MemoryStream())

{

doc.Save(ms, SaveFormat.Rtf);

ms.Position = 0;

doc = new Document(ms);

}

// Get all cells.

NodeCollection cells = doc.GetChildNodes(NodeType.Cell, true);

foreach (Cell cell in cells)

{

if (cell.CellFormat.Shading.ForegroundPatternColor != Color.Empty)

{

// Reset color of text insode the cell

NodeCollection runs = cell.GetChildNodes(NodeType.Run, true);

foreach (Run run in runs)

run.Font.Color = Color.White;

}

}

doc.Save(@"Test001\out.html");

Hope this helps.

Best regards,

Hello Alexey,

thank you very much for your quick reply and the proposed workaround.

The conversion into RTF works perfectly and now even my existing solution works again, since it already checked the ForegroundColorPattern of cells.

Thanks again, that was a big issue of which I thought, i could not handle it for a while.
You guys are doing a very good job.

Keep on going and have a nice day,
Wolfgang

Hi Wolfgang,

It is perfect that the proposed workaround helped. We will let you know once the original issue is resolved.

Please feel free to ask in case of any issues. We are always glad to help you.

Best regards,

The issues you have found earlier (filed as WORDSNET-5057) have been fixed in this .NET update and in this Java update.