tcpdf (html2pdf) is not generating table borders correctly

renathy picture renathy · Sep 7, 2013 · Viewed 14.9k times · Source

I am generating pdf file using html2pdf (that is using tcpdf library, _tcpdf_5.0.002). Unfourtunately I cannot generate table borders properly.

require_once('inc/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','en');
$pdf_output = '';

// HEADER
$pdf_output .='<page backtop="8mm" backbottom="8mm" backleft="10mm" backright="10mm" style="font-size: 11px;font-family:freeserif;">';
$pdf_output .= '<style> 
    table {
        border-collapse:collapse;
    }
    </style>';

 $pdf_output.='<table>';
 $pdf_output.= '<tr><td style="border-top: 1px solid black;">A</td></tr>';
 $pdf_output.= '<tr><td style="border-top: 1px solid black;">A</td></tr>';
 $pdf_output.= '<tr><td style="">A</td></tr>';
 $pdf_output.= '<tr><td style="border-top: 1px solid black;">A</td></tr>';
 $pdf_output.='</table>';
 $pdf_output .='</page>';
 $html2pdf->WriteHTML($pdf_output);
 $attachment= $html2pdf->Output('attachment.pdf', 'S');
 ...

It doesn't show top borders for cells. It shows top-border only for first row and not for others. I have simplified this html markup for test purposes (in reality it doesn't render just "A" letters in one cell, there is content in differnt columns, but top-border is not rendering either).

How to render top-border for cells ucing html2pdf (tcpdf)?

Answer

R3tep picture R3tep · Jun 29, 2017

Another workaround is to replace the css property border-collapse: collapse; by cellspacing="0"

<table cellspacing="0">

Reference