Word to HTML - Table Border Width Issues

I’m running into issues with the Word to HTML conversion with a table present. A Border Width defined at 0.5 points does not render properly.

I’ve attached a document here with 2 tables. The first is a table with a Border Width that is by default set at ½ (0.5) points. The second identical but set to 0.75 points.

When this gets rendered to html, it is converted literally, so the css that is applied to the cell will be 0.5pt and 0.75 respectively for the two tables. This is problematic because the 0.5pt is too small and renders nothing at my default zoom level (If I zoom the text, I will see the border). Please see resulting_html.txt for the generated html for this conversion. Save it as an HTML file to see how it will look in Chrome, FF, IE… You can also look at resulting_html_render.png to see what my output is.

Investigating this further…

When I look at the document manually, I wanted to and get all the way down to the Table’s Cell level and look at the CellFormat.Borders property

Aspose.Words.Document doc = new Aspose.Words.Document("C:/aspose_errors/border_testing.docx");

NodeCollection nodes = doc.GetChildNodes(NodeType.Table, true);

foreach(Node node in nodes)
{
    Aspose.Words.Tables.Table table = node as Aspose.Words.Tables.Table;
    foreach(Aspose.Words.Tables.Row row in table.Rows)
    {
        foreach(Aspose.Words.Tables.Cell cell in row.Cells)
        {
            foreach(Aspose.Words.Border border in cell.CellFormat.Borders)
            {
                // **First table has a border.LineWidth of 0.0 when it parses through here**
                // Second table has a border.LineWidth of 0.75 when it parses through here
            }
        }
    }
}

The first table has a border.LineWidth of 0.0! I’m not sure if you have some failsafes in your code that actual translate the line width to a minimum of 0.5 or not, do you?

That aside though, if the 0.5pt is coming through is there a way in which I can tell the save process to use em or px instead of pt? I can of course manually parse the final html result manually to adjust the pt to em (or px).

Hi Philip,

Thanks for your inquiry.

The problem occurs because the Html produced doesn’t contain a DOCTYPE element. When a browser (e.g. Internet Explorer 9) doesn’t find a DOCTYPE element in a document it switches to compatibility mode and changes some rendering rules. Aspose.Words’ Html exporting engine is not designed to support rendering a document in compatibility mode. As a result, the document renders incorrectly. To include a DOCTYPE element in Html document please export it with HtmlSaveOptions.ExportXhtmlTransitional property set to true. Please see the following workaround:

Document doc = new Document(@"C:\Temp\input.docx");
doc.Save(@"C:\Temp\out.html", new HtmlSaveOptions
{
    ExportXhtmlTransitional = true
});

If we can help you with anything else, please feel free to ask.

Hi Philip,

Further to my last post, I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-8711 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

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

This message was posted using Notification2Forum from Downloads module by aspose.notifier.