Unbroken text within HTML tables is not wrapping

During our last Aspose.Words for .NET upgrade (15.8.1 - 19.6) we noticed that the HTML tables are no longer being confined to the expected widths when the table contains long portions of unbroken text, resulting in the contents running off of the page.

Investigation has shown that the document will render correctly if the tables Automatically resize to fit contents property is de-selected when the document is generated as a Word document, so we’d like to be able to apply this setting within our code. Is this possible when inserting tables as HTML?

If this isn’t possible we’d hope to be able to find some effective CSS that we could apply to the HTML for the same effect, as nothing I’ve tried has made any difference.

Is there a recommended way to address this issue?

A simplified demonstration of what we are doing can be found here in C#.

using System.Text;
using Aspose.Words;

namespace Aspose
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();
            CreateTable(sb, "Single line content", "Spaced content on a single line");
            CreateTable(sb, "Multi line content", "Spaced content across multiple lines. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum");
            CreateTable(sb, "Unbroken content", "https://www.abc.ac.uk/media/wwwtrwcuk/research/images/Research%20PLAN%20Management%20Policy%20Principles%20Code%20of%20Good%20Practice.pdf");
        
        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);

        builder.InsertHtml(sb.ToString());
        doc.UpdateTableLayout();

        // Save doc
        doc.Save("asposetest.pdf", SaveFormat.Pdf);

        void CreateTable(StringBuilder builder, string header, string content)
        {
            builder.AppendLine("<table style ='width:100%;max-width:100%;'>");
            builder.AppendLine($"<tr><th>{header}</th></tr>");
            builder.AppendLine($"<tr><td>{content}</td></tr>");
            builder.AppendLine("<br/><br/>");
        }
    }
}

}

@bobkeith

There is no need to call Document.UpdateTableLayout method. Please call CompatibilityOptions.OptimizeFor method as shown below to get the desired output. Hope this helps you.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertHtml(sb.ToString());
                
doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2019);
doc.Save(MyDir + "21.10.pdf", SaveFormat.Pdf);

Hi @tahir.manzoor
Thank you for the quick response. This did fix the issue in the sample code I provided, but unfortunately I have realised that something else is affecting things within our codebase, where a similar problem exists.

We allow users to provide their own template files from which the PDFs are generated. Traditionally these have been .doc files, which work but when they use the same template saved as a .docx file I see the behaviour where the table is being pushed out by the presence of long text.

Is this an issue you’re familiar with at all?

Many thanks

@bobkeith

Please ZIP and attach your DOCX template document along with HTML that you want to insert in it. We will investigate the issue and provide you more information on it.

Thanks again @tahir.manzoor,
I’m having difficulty recreating this succinctly but if I manage to I will make sure to send on the issue.

@bobkeith

As soon as you get ready the requested resouces, we will start investigation into your issue and provide you more information. Thanks for your cooperation.