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/>");
}
}
}
}