Hi,
We need convert html string to pdf and word documents. Some cells in html has rowspan and colspan properties.
The part of code we use:
Document document = new Document(); DocumentBuilder builder = new DocumentBuilder(document); string htmlContent = @"<!DOCTYPE html> <html lang='ru'> <head> <title>Title</title> </head> <body> <div> <table border='1'> <tr> <td rowspan='3'>Test1</td> <td rowspan='3'>Test2</td> <td colspan='7'>Test3</td> <td rowspan='3'>Test4</td> </tr> <tr> <td colspan='2'>Test5</td> <td colspan='2'>Test6</td> <td colspan='2'>Test7<br>Test8</td> <td rowspan='2'>Test9</td> </tr> <tr> <td>Test10<br>Test11</td> <td>Test12</td> <td>Test13</td> <td>Test14</td> <td>Test15</td> <td>Test16<br>Test17<br>Test18</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> <td>7</td> <td>8</td> <td>9</td> <td>10</td> </tr> <tr> <td>String1</td> <td>String2</td> <td>String3</td> <td>String4</td> <td>String5</td> <td>String6</td> <td>String7</td> <td>String8</td> <td></td> <td>String9</td> </tr> <tr> <td> </td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td> </td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td> </td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </div> </body> </html>"; builder.InsertHtml(htmlContent); builder.PageSetup.Orientation = Orientation.Landscape; NodeCollection tables = builder.Document.GetChildNodes(NodeType.Table, true); foreach (Aspose.Words.Tables.Table table in tables) { if (table.AllowAutoFit) { table.AutoFit(AutoFitBehavior.FixedColumnWidths); } } document.Save($"C:/test/Report.pdf", Aspose.Words.SaveFormat.Pdf);
In result, created file (pdf) contains incorrect table, last column doesn’t have merged cell, right border of table is broken. Pleese see attached file Report_incorrect_with_AutoFit.pdf.
Table is correct after deleting code line with method AutoFit (see Report_correct.pdf)
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
Why method AutoFit breaks table with merged cells? How we can use AutoFit and merged cells together?
Thanks for your help.
Report_correct.pdf (20.5 KB)
Report_incorrect_with_AutoFit.pdf (20.5 KB)