HTML2PDF doesn't recognize tables' sizes

筅森魡賤 提交于 2020-05-11 04:56:46

问题


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?


回答1:


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




回答2:


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

<col width="250">
<col width="500">
<col width="250">



回答3:


I have the same problem and I changed the page margins, especially on the right side

page backtop="14mm" backbottom="14mm" backleft="8mm" backright="100mm"



来源:https://stackoverflow.com/questions/17314992/html2pdf-doesnt-recognize-tables-sizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!