Reduce the table width when table width is more than page width

Hi,

We are converting html to pdf and these html will be generated from rich text editor.

Please suggest a fix where we could identify any table which is getting cut or it’s width is more than page and adjust it.

Below is the code we are using to convert html to pdf.

using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(File.ReadAllText(@“C:\Users\msingh02\Desktop\wideImageIssueWithTable.html”))))
{
Aspose.Words.Document docw = new Aspose.Words.Document(memoryStream, new LoadOptions(LoadFormat.Html, null, null));
foreach (Aspose.Words.Section sec in docw.Sections)
{
Aspose.Words.PageSetup ps = sec.PageSetup;
// 1 inch equals 72 points
ps.TopMargin = 0;
ps.RightMargin = 0;
ps.BottomMargin = 0;
ps.LeftMargin = 0;
ps.PageWidth = Aspose.Pdf.Generator.PageSize.A4Width;
ps.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height;
}

docw.Save("d:\\outputInk6New2.pdf");

Table width issue.zip (55.0 KB)
Thanks,
Mukesh Singh

@msingh02

Thanks for your inquiry. Please set the table’s width as shown below to get the desired output. Hope this helps you.

Document html = new Document(MyDir + "wideImageIssueWithTable.html");
foreach (Table table in html.GetChildNodes(NodeType.Table, true))
{
    table.PreferredWidth = PreferredWidth.FromPercent(100);
}
                 
html.Save(MyDir + "18.10.pdf");