当分配给 DOMPDF 生成的 PDF 文件中的 td 标签时,CSS 边框线不显示

发布于 2024-12-05 09:37:21 字数 2158 浏览 0 评论 0原文

我正在使用 DomPDF 0.6 渲染表格,现在我需要在每个单元格中都有边框。如果我使用,则单元格填充和单元格间距会影响边框的宽度,因此我无法使用它。

现在我有了我的表格

$html = '<table border="0" cellspacing="0" cellpadding="4" width="100%" style="border:1px solid #000;">
                <tr>
                    <td class="borderOk">&nbsp;</td>
                    <td class="borderOk" align="center" colspan="2" style="font-size:18px;font-weight:normal;"><i>'.$pName1.'</i></td>
                    <td class="borderOk" align="center" colspan="2" style="font-size:18px;font-weight:normal;"><i>'.$pName2.'</i></td>
                </tr>
                <tr>
                    <td class="borderOk"><strong><i>Price</i></strong></td>
                    <td class="borderOk" colspan="2" >&nbsp;</td>
                    <td class="borderOk" colspan="2" >&nbsp;</td>
                </tr>
                <tr>
                    <td class="borderOk"><strong><i>Options</i></strong></td>
                    <td class="borderOk" colspan="2" >&nbsp;</td>
                    <td class="borderOk" colspan="2" >&nbsp;</td>
                </tr>
                <tr>
                    <td class="borderOk" >&nbsp;</td>
                    <td class="borderOk" colspan="2" >&nbsp;</td>
                    <td class="borderOk" colspan="2" >&nbsp;</td>
                </tr>
</table>';

,我的样式看起来像这样“也在顶部的 $html 变量内”

<style type="text/css">

    td .borderOk{  
     border-style: solid;
     border-width: 1px;
     border-color: #A5C3E0;
}
</style>

边框在我的浏览器中完美显示,但是当使用 domPDF 渲染它时,pdf 文件显示没有内部 td 边框,只有轮廓显示边框。

我的 DomPDF 代码如下所示

$dompdf = new DOMPDF();

$dompdf->load_html($_SESSION['html'],'UTF-8');
$dompdf->set_paper('a4', 'portrait');
$dompdf->render();
$dompdf->stream(date("YmdHis").".pdf");

I'm rendering a table using DomPDF 0.6, now I need to have borders throughout each cell. If I use then the cellpadding and cellspacing affects the width of the border so I can't use it.

Now I have my table

$html = '<table border="0" cellspacing="0" cellpadding="4" width="100%" style="border:1px solid #000;">
                <tr>
                    <td class="borderOk"> </td>
                    <td class="borderOk" align="center" colspan="2" style="font-size:18px;font-weight:normal;"><i>'.$pName1.'</i></td>
                    <td class="borderOk" align="center" colspan="2" style="font-size:18px;font-weight:normal;"><i>'.$pName2.'</i></td>
                </tr>
                <tr>
                    <td class="borderOk"><strong><i>Price</i></strong></td>
                    <td class="borderOk" colspan="2" > </td>
                    <td class="borderOk" colspan="2" > </td>
                </tr>
                <tr>
                    <td class="borderOk"><strong><i>Options</i></strong></td>
                    <td class="borderOk" colspan="2" > </td>
                    <td class="borderOk" colspan="2" > </td>
                </tr>
                <tr>
                    <td class="borderOk" > </td>
                    <td class="borderOk" colspan="2" > </td>
                    <td class="borderOk" colspan="2" > </td>
                </tr>
</table>';

With my styles that look like this "Also is within the $html variable at the top"

<style type="text/css">

    td .borderOk{  
     border-style: solid;
     border-width: 1px;
     border-color: #A5C3E0;
}
</style>

The borders show perfectly in my Browser but when rendering it using domPDF the pdf file shows without the inner td borders, only the outline border is shown.

My DomPDF code looks like this

$dompdf = new DOMPDF();

$dompdf->load_html($_SESSION['html'],'UTF-8');
$dompdf->set_paper('a4', 'portrait');
$dompdf->render();
$dompdf->stream(date("YmdHis").".pdf");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-12-12 09:37:22

尝试使用dompdf版本0.6.0 beta3。它肯定会起作用。我已经尝试过你的代码。

http://code.google.com /p/dompdf/downloads/detail?name=dompdf_0-6-0_beta3.tar.gz

Try to use dompdf version 0.6.0 beta3. It will work for sure. I had tried your code.

http://code.google.com/p/dompdf/downloads/detail?name=dompdf_0-6-0_beta3.tar.gz

眉目亦如画i 2024-12-12 09:37:21

您的 CSS 选择器应该是

td.borderOk

(没有空格)

或者更好:将 <​​code>borderOK 类添加到表格中,并保持 CSS 不变。

Your CSS selector should be

td.borderOk

(without the space)

Or better : add the borderOK class to the table and leave your CSS as it is.

凹づ凸ル 2024-12-12 09:37:21

我有同样的问题。删除 border="0",然后按照 Fabien 的说明进行操作:td.borderOk 或只是 .borderOk

I had the same issue. Remove the border="0" then do as Fabien noted: td.borderOk or just .borderOk

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文