HTML2PDF doesn't recognize tables' sizes
Asked Answered
F

3

12

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?

Foredate answered 26/6, 2013 at 8:21 Comment(1)
i am having the same problem. style or width does not work on table cellHolocaine
W
15

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

Worley answered 26/6, 2013 at 8:29 Comment(2)
Yep, it worked! Using the style attribute inside the 'table' tag works perfectly... thanks, Raphael! I'm marking your post as an answer! :)Foredate
Guess I wouldn't mind if this were mentioned on the GitHub page. It's not exactly obvious that you are not allowed to use the CSS file for table borders (and possibly other things). (I know that the question wasn't specifically about the .css file, but I find that when you include border formatting for table elements in the .css file, it doesn't work either - moving to inline style does.) Cost me a couple of hours.Chimera
C
4

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

<col width="250">
<col width="500">
<col width="250">
Compressibility answered 5/9, 2017 at 4:58 Comment(1)
Using style as suggested in selected answer didn't work but this works like a charm, thanks !Colorant
A
-1

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"

Autry answered 5/6, 2014 at 2:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.