I'm trying to use HTMLRenderer and PDFSharp to output a PDF file. But I'm noticing that even very simple tables don't render correctly. I embed the style right in the web page. I even tried style tags right on the elements and it ignores them.
Am I missing something here?
using PdfSharp.Pdf;
using System.IO;
using TheArtOfDev.HtmlRenderer.PdfSharp;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
string html = File.ReadAllText(@"1.htm");
PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.Letter);
pdf.Save(@"1.pdf");
}
}
}
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<style>
.hdr { background-color:gray;}
.cell {background-color:burlywood;}
tr { color:blue;}
</style>
</head>
<body>
<table>
<tr class="hdr"><td>Colum1</td><td>Column2</td></tr>
<tr style="background-color: lightblue"><td>Chevy</td><td>Malibu</td></tr>
<tr><td class="cell">Honda</td><td style="background-color:gold">Accord</td></tr>
</table>
</body>
</html>
Output of browser on top and PDF on bottom: