为什么边界折叠在html2pdf中有效? [英] Why doesn't border-collapse work in html2pdf?

查看:58
本文介绍了为什么边界折叠在html2pdf中有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个带有html表的pdf文件,例如:

I want to create a pdf with an html table like :

所以,我创建了这个html:

So, I created this html :

<table style="width: 100%; border:2px solid; border-collapse: collapse; padding: 0; margin: 0;">
    <tr style="border-bottom: 1px solid;">
        <th style="border-left: 1px solid; width: 60%;">Ref produit</th>
        <th style="border-left: 1px solid; width: 10%;">Taille</th>
        <th style="border-left: 1px solid; width: 10%;">Quantit�</th>
        <th style="border-left: 1px solid; width: 10%;">Prix net HT</th>
        <th style="border-left: 1px solid; width: 10%;">Montant HT</th>
    </tr>
    <tr>
        <td style="border-left: 1px solid;">BAL100</td>
        <td style="border-left: 1px solid; text-align: center;">S</td>
        <td style="border-left: 1px solid; text-align: center;">20</td>
        <td style="border-left: 1px solid; text-align: center;">22.00</td>
        <td style="border-left: 1px solid; text-align: center;">440</td> 
    </tr>
    <tr>
    .
    .
    .
    </tr>
</table>

pdf结果为:

边界消失了!

如果我删除属性 border-collapse:塌陷; ,则会出现边框,但结果不合适.

If I remove the property border-collapse: collapse; the borders appear but the result is not appropriate.

我在官方论坛上看到(法语后)属性border-collapse仅适用于标签 table .所以我不明白为什么我的表生成不正确.

I see on the official forum (french post) that the property border-collapse works only on the tag table. So I don't understand why my table is not generated properly.

有什么主意吗?

这是我的生成pdf的php代码

Here is my php code to generate the pdf

$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($htmlContent);
$html2pdf->Output($path, 'F');

推荐答案

边界折叠:折叠; 应该将两个相同的相邻边界合并在一起.在html2pdf中使用它时,应同时设置 border-left border-right 属性的样式(相同),折叠时将产生单个边框.另外,要防御性地编写此CSS,而不假定 border-color 属性是继承的,则应在定义边框时从技术上指定它,例如 border:1px纯黑;

border-collapse: collapse; is supposed to merge two of the same, adjacent borders together. When using it in html2pdf, you should style both the border-left and border-right attributes (as the same thing), which when collapsed will produce a single border. Also, to write this CSS defensively, and not assume the border-color attribute inheritance, you should technically specify it when defining border, such as border: 1px solid black;

这篇关于为什么边界折叠在html2pdf中有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆