HTML2PDF doesn't recognize tables' sizes

Johanovski picture Johanovski · Jun 26, 2013 · Viewed 30k times · Source

I'm working in a web page developed using Yii Extension and I'm using the HTML2PDF extension to generate PDFs (http://html2pdf.fr/). Though the PDF is generated fine, it doesn't seem to recognize my tables' sizes; doesn't matter the width or height I specify for a row or a whole table: the PDF is always generated the same way (with a table width that just fits the cell content)... Here is how I'm trying to specify the width:

<table width="500px" height="20px" style="margin:10px;">
                    <tr>
                        <td width="25%"></td>
                        <td width="50%"></td>
                        <td width="25%"></td>
                    </tr>
                    <tr bgcolor="#EAF8FF">
                        <td colspan="3">
                            <strong>Title</strong>
                        </td>
                    </tr>

I've tried specifying the width with:

  • pixels ("500px")
  • percentage ("100%")
  • without 'px' ("500")
  • using the '& quot;' tag (yes, I'm aware there is an extra space between '&' and 'quot')

... etc. but nothing seems to matter... The table size and width is always proportional to the text it contains. However, both the "bgcolor" in the 'tr' tag and the "colspan" in the 'td' tag work fine, so I don't know what can be happening... I've also tried specifying the size inside the 'tr', but nothing... Any idea on what can I be missing?

Answer

Rapha&#235;l picture Raphaël · Jun 26, 2013

Have you tried with "style" attribute? All examples on html2pdf wiki is with this attribute : http://wiki.spipu.net/doku.php?id=html2pdf:en:v4:bookmark&s[]=td&s[]=width