Html HTML2PDF 无法识别表格的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17314992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML2PDF doesn't recognize tables' sizes
提问by Johanovski
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:
我正在使用 Yii Extension 开发的网页中工作,并且我正在使用 HTML2PDF 扩展来生成 PDF(http://html2pdf.fr/)。尽管 PDF 生成得很好,但它似乎无法识别我的表格大小;我为一行或整个表格指定的宽度或高度无关紧要:PDF 总是以相同的方式生成(表格宽度恰好适合单元格内容)......这是我试图指定的方式宽度:
<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')
- 像素(“500px”)
- 百分比(“100%”)
- 没有“px”(“500”)
- 使用“& quot;” 标签(是的,我知道“&”和“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?
...等等,但似乎没什么关系...表格的大小和宽度总是与其包含的文本成正比。但是,“tr”标签中的“bgcolor”和“td”标签中的“colspan”都可以正常工作,所以我不知道会发生什么......我也试过在里面指定大小'tr',但什么都没有......我知道我会错过什么吗?
回答by Rapha?l
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
您是否尝试过“样式”属性?html2pdf wiki 上的所有示例都具有此属性:http://wiki.spipu.net/doku.php?id=html2pdf:en:v4:bookmark&s[]=td&s[]=width
回答by Luke Wenke
You can also use "col" tags after the opening "table" tag. e.g.
您还可以在打开“table”标签后使用“col”标签。例如
<col width="250">
<col width="500">
<col width="250">
回答by user3699058
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"
页面 backtop="14mm" backbottom="14mm" backleft="8mm" backright="100mm"