Why doesn't border-collapse work in html2pdf?

你说的曾经没有我的故事 提交于 2019-12-08 14:32:08

问题


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

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>

The pdf result is:

The borders disappeared!

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

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.

Any idea?

Here is my php code to generate the pdf

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

回答1:


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;




回答2:


I found a workaround, if I replace the css property border-collapse: collapse; by cellspacing="0" the result looks OK.

<table cellspacing="0" style="width: 100%; border:2px solid;position: relative;">


来源:https://stackoverflow.com/questions/29645767/why-doesnt-border-collapse-work-in-html2pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!