iTextSharp + xmlworker is not drawing well the width of columns in a table

229 Views Asked by At

I have this html table: original html

  • This table has table-layout: auto and width: 100%
  • None of the cells has a defined width
  • As you can see, the width of each column is automatically adjusted to the best fit, by the browser

When I convert it to PDF with xmlworker 5.5.3 (iTextSharp 5.5.3), I get this PDF: xmlworker html to pdf

As you can see, iTextSharp has decided very bad the widths for the columns (compare it to how Chrome draws the table): Drawing wrong the widths of cells

It is not efficient:

  • Large columns are drawn too narrow (eg. 4th column)
  • Short columns are drawn too wide

I tried other "html to pdf" tools and they do well with the width of the columns:

pupeeter (Chrome headless): pupeeter html to pdf

wkhtmltopdf: wkhtmltopdf.exe html to pdf

But what I like about iTextSharp is that I can use it directly on my web app hosted in Azure.

  • puppeteer is made in node.js and my web app is made in C# / asp.net
  • wkhtmltopdf needs to run in a B1 tier in Azure (expensive)

So... what am I doing wrong with xmlworker? or it is simply a bad library?

UPDATE 1

There is a puppeteer project for C# called "PuppeteerSharp". I'm trying now. Apparently it needs to be run along with browserless.io because Azure won't run Chrome on a web app (F1 at least...)

UPDATE 2

Not easy to run PuppeteerSharp in Azure.
For now, I deployed the GitHub project "url-to-pdf-api" in heroku, which uses Puppeteer, and I'm calling this from Azure. Not fast, not simple...

UPDATE 3

I tried updating from xmlworker 5.5.3 to xmlworker 5.5.13.2 and its even worse. It doesn't consider style="width: 25%" on <td> (which 5.5.3 does OK). What a terrible library

0

There are 0 best solutions below