【问题标题】:Table well displayed in html but not in the pdf generated with mpdf表格很好地显示在 html 中,但不在使用 mpdf 生成的 pdf 中
【发布时间】: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 = '&lt;style&gt;'.file_get_contents('cn.css').'&lt;/style&gt;';你必须告诉mdpf这是css
  • 是的,我做了,对于mpdf,参数1意味着它是一个css,我也尝试过像你说的那样使用。当我添加另一种样式时,它会被考虑,所以我认为这不是问题
  • hmmm,你能把mpdf代码贴出来吗?

标签: php html mpdf


【解决方案1】:

我已经找到了解决方案,我没有给出 % ,而是给出了 px 的宽度并且它起作用了。 结论:mPDF 不支持 %(宽度:33%;对于我的示例)但支持 px(宽度:100px;对于我的示例)。 ;) ;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 2017-06-19
    • 2018-02-04
    • 2020-02-08
    • 2022-12-30
    • 1970-01-01
    相关资源
    最近更新 更多