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

Free Support Forum - aspose.com

Border do not appear with latest version

Hi,

We have recently updated our version of aspose words .net to the latest version and have noticed that all of our tables are now being rendered without borders. We are rendering all of our word output using the insert html option and then converting our word document into PDF format. Any help would be appreciated as this is an urgent issue.

Code:

Aspose.Words.Document document = new Aspose.Words.Document(); 
var builder = new Aspose.Words.DocumentBuilder(document); 
builder.InsertHtml(@" <table style=""width:100%""> <td style=""color:Black;border-width:1px;padding:4px;""> <p style=""width:100%"">This is sample content <td style=""color:Black;border-width:1px;padding:4px;""> <p style=""width:100%"">More Content "); 
document.Save("C:/Development/samplefile.doc"); 

That’s the code, this previously rendered with borders but with the new version no borders appear. The issue we have is we have thousands of lines of code that are using the above technique and we cant go through each of these and fix them somehow.

This message was posted using Email2Forum by Babar Raza.

Hi Graeme,

Thanks for your inquiry.
Please note that Aspose.Words mimics the same
behavior as MS Word does. If you convert your document to HTML using MS
Word, you will get the same output. So, this is not an issue. You are facing the expected behavior of Aspose.Words.

Please modify the html style as highlighted in following code example.

Document document = new Document();
var builder = new DocumentBuilder(document);
builder.InsertHtml(@" <td style='color:Black;border-width:1px;border-color:black;border-style: solid;'> 
This is sample content
<td style='border: 1px solid black;padding:4px;'> 
More Content
");
document.Save(MyDir + "samplefile.doc");
document.Save(MyDir + "samplefile.pdf");

Hi is this the only way to get borders on the tables. We have an extensive system which has been build around similar code to the provided example so potentially thousands of places to change this on tables.

We also have areas where we are adding tables through the builder object that are affected in the same way. How do we fix all of this.

On top of this we have noticed that fonts are coming out differently that they were before. Has this changed as well.

Hi Graeme,

Thanks for your inquiry.

Please note that Aspose.Words mimics the same
behavior as MS Word does. Please open your shared html in your first post in MS Word (or browser), you will see there is no border of table. You need to change the styles for TD tag according to your requirement or add ‘border’ property of table in table tag.

Hope this helps you. Please let us know if you have any more queries.

Can you please confirm that this behavior has changed between versions and that there is not some setting we have missed as our previous version of aspose words was rendering borders with the above example throughout our system.

Hi Graeme,

Thanks for your inquiry. The behaviour of Aspose.Words is correct in latest version. Perhaps, there was issues in older version of Aspose.Words. Could you please share which older version you are using? I will check the scenario and provide you more information about your query.

Hi we were using Aspose words .net 11.5

We have previously carried out multiple upgrades of aspose throughout the life of our software and the borders have been present until this release.

Further to this, the code we implemented to show borders on tables was taken from guidance from your website (at the time).

Please can you make the developers aware that by changing this default functionality they are making it very difficult if not impossible for their clients to upgrade as I m sure there will be others in our situation.

Hi Graeme,

Thanks for your inquiry. This was an issue
in older version of Aspose.Words and have fixed in latest versions. Please note that Aspose.Words mimics the same behavior as MS Word does. The behavior of Aspose.Words in older versions is incorrect. I suggest you please modify the styles in your Html as shown in my previous post and use latest version of Aspose.Words for .NET 14.10.0.

Please let us know if you have any more queries.

Hi, for reference we found the ability to override default behaviour by using the below class, however, when we try to access the border properties of a table cell, an error is thrown from within the getter/setter for the LineWidth property (and any other properties of a border).

In order to have this work, we need to be able to detect if a border width has been set on a table cell, so that we can identify if we should apply further formatting to the cell.

Is there a way to get/set border properties on a cell at this point?

private class NodeChanger : INodeChangingCallback
{
    public void NodeInserted(NodeChangingArgs args)
    {
        if (args.Node.NodeType == NodeType.Run)
        {
            Aspose.Words.Font font = ((Run)args.Node).Font;
            font.Name = "Arial";
        }
        else if (args.Node.NodeType == NodeType.Cell)
        {
            Aspose.Words.Tables.Cell cell = ((Aspose.Words.Tables.Cell)args.Node);

            if (cell.CellFormat.Borders.LineWidth > 0)
            {
                cell.CellFormat.Borders.LineStyle = LineStyle.Single;
                cell.CellFormat.Borders.LineWidth = 0.5;
                cell.CellFormat.Borders.Color = Color.Black;
            }
        }
    }

    public void NodeInserting(NodeChangingArgs args) { }

    public void NodeRemoved(NodeChangingArgs args) { }

    public void NodeRemoving(NodeChangingArgs args) { }
}

In addition, if I iterate through these properties after the document has been generated, the underlying linewidth has not been set, even though a border-width style has been applied to the table cell. I understand that the linestyle and color have not been set because the HTML does not reference those, however, I expect that the linewidth should be populated because it has been specified, can you explain how these properties are set?

Hi Graeme,

Thanks for your inquiry.
Please use the latest version of Aspose.Words for .NET 14.10.0 and use following code example to achieve your requirements.

Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
NodeChanger nodechanger = new NodeChanger();
// Set up and pass the object which implements the handler methods.
doc.NodeChangingCallback = nodechanger;
builder.InsertHtml(@"This is sample content More Content ");
foreach (Cell cell in nodechanger.cells)
{
    cell.CellFormat.Borders.LineStyle = LineStyle.Single;
    cell.CellFormat.Borders.LineWidth = 0.5;
    cell.CellFormat.Borders.Color = Color.Black;
}
doc.Save(MyDir + "samplefile.doc");
doc.Save(MyDir + "samplefile.pdf");
class NodeChanger : INodeChangingCallback
{
    public ArrayList cells = new ArrayList();

    public void NodeInserted(NodeChangingArgs args)
    {
        if (args.Node.NodeType == NodeType.Run)
        {
            Aspose.Words.Font font = ((Run)args.Node).Font;
            font.Name = "Arial";
        }
        else if (args.Node.NodeType == NodeType.Cell)
        {
            Aspose.Words.Tables.Cell cell = ((Aspose.Words.Tables.Cell)args.Node);
            if (cell.CellFormat.Borders.LineWidth > 0)
            {
                cells.Add(cell);
            }
        }
    }
    public void NodeInserting(NodeChangingArgs args) { }

    public void NodeRemoved(NodeChangingArgs args) { }

    public void NodeRemoving(NodeChangingArgs args) { }
}