【发布时间】:2014-05-24 18:53:13
【问题描述】:
我正在尝试使用 mPDF 在 PHP 中生成 PDF。
我的文档的一部分必须是这样的:
(来源:cloudandfun.com)
所以我为 HTML 写了:
<table style = "width:100%">
<tr>
<td>Appellation <br>(par ordre de préférence)</td>
<td style = "border:0px;">
<table style = "width:100%; border:0px;">
<tr style = "border:0px;"><th style = "border:0px;">Abréviation (S’il y a lieu)</th></tr>
</table>
<table style = "width:100%;border:0px;">
<tr style = " border:0px;">
<td style = "width:33%;border-bottom:0px;border-left:0px;">Abréviation</td>
<td style = "width:33%;border-bottom:0px;border-left:0px;">Facultative</td>
<td style = "width:33%;border-bottom:0px;border-left:0px;border-right:0px;">Obligatoire</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>1.</td>
<td>
<table style = "width:100%;border:0px;">
<tr style = " border:0px;">
<td style = "width:33%;border-bottom:0px;border-left:0px;border-top:0px;">--</td>
<td style = "width:33%;border-bottom:0px;border-left:0px;border-top:0px;">--</td>
<td style = "width:33%;border:0px;">--</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>2.</td>
<td>
<table style = "width:100%;border:0px;">
<tr style = " border:0px;">
<td style = "width:33%;border-bottom:0px;border-left:0px;border-top:0px;">--</td>
<td style = "width:33%;border-bottom:0px;border-left:0px;border-top:0px;">--</td>
<td style = "width:33%;border:0px;">--</td>
</tr>
</table>
</td>
</tr>
我的 CSS:
th,td,tr {
border:1px solid black;
border-collapse:collapse;
}
table {
border:2px solid black;
border-collapse:collapse;
}
td {
font-family:Arial;
font-size:11px;
}
在html页面中,效果很好,但是生成pdf的时候是这样的:
(来源:cloudandfun.com)
有人对此有解决方案吗?提前致谢。
【问题讨论】:
-
尝试将样式信息放入附加到页面的 css 表中,然后再次尝试打印,看看是否有帮助。 MPDF 可能无法阅读
style = "width:33%;border:0px;,并且更喜欢其他格式。反正这是我的猜测。 -
感谢您的回答。我把那个 css 放在 css 表中,并在 mpdf 中调用它,如 $stylesheet = file_get_contents('cn.css'); $mpdf->WriteHTML($stylesheet,1);但这并不能解决问题。
-
你试过
$stylesheet = '<style>'.file_get_contents('cn.css').'</style>';你必须告诉mdpf这是css -
是的,我做了,对于mpdf,参数1意味着它是一个css,我也尝试过像你说的那样使用。当我添加另一种样式时,它会被考虑,所以我认为这不是问题
-
hmmm,你能把mpdf代码贴出来吗?