Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML2PDF doesn't recognize tables' sizes

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?

like image 601
Johanovski Avatar asked Jun 26 '13 08:06

Johanovski


2 Answers

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

like image 51
Raphaël Avatar answered Sep 19 '22 11:09

Raphaël


You can also use "col" tags after the opening "table" tag. e.g.

<col width="250">
<col width="500">
<col width="250">
like image 40
Luke Wenke Avatar answered Sep 22 '22 11:09

Luke Wenke