When loading an HTML file where the root html element has height 100%, and there is a nested table with width 100%, long lines of text in the nested table aren’t wrapped correctly.
If a page width is specified, the contents of the nested table are clipped instead of wrapped.
If no page width is specified, the resulting PDF has a page size wide enough to contain the long lines of text without any line breaks.
We are getting html generated like this from an external system, so we would prefer not to have to manipulate the html.
Sample code:
var htmlString = @"<!DOCTYPE html>
<html style=""height: 100%"">
<head>
</head>
<body>
<table>
<tbody>
<tr>
<td>
<table style=""width: 100%"">
<tbody>
<tr>
<td>
long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text
</td>
</tr>
</tbody>
</table>
<br>
</td>
</tr>
</tbody>
</table>
</body>
</html>";
using (var ms = new MemoryStream())
{
using (var sw = new StreamWriter(ms, Encoding.UTF8, 1024, true))
{
sw.Write(htmlString);
sw.Flush();
ms.Seek(0, SeekOrigin.Begin);
}
using (var doc = new Document(ms, new HtmlLoadOptions()
{
PageInfo = new PageInfo()
{
Height = PageSize.A4.Height,
Width = PageSize.A4.Width,
}
}))
{
doc.Save("clipped.pdf");
}
}