How to display tables in pdf with the MPDF library?

1

I have a html that is automatically generated by a wysiwyg component (a text editor) and inside one of the texts that I generated, it has a table and this table usually appears in html, however I need this table to appear in pdf I'm generating.

PDF is coming out like this:

AndIwantedittocomeoutlikethisinmyhtml:

<?phpsession_start();include('mpdf60/mpdf.php');$mpdf=newmPDF('',//mode-default'''',//format-A4,forexample,default''0,//fontsize-default0'',//defaultfontfamily15,//margin_left15,//marginright58,//margintop0,//marginbottom6,//marginheader0,//marginfooter'L');//L-landscape,P-portrait$mpdf->SetDisplayMode('fullpage');$paragrafo="<p style=\"text-align:justify;line-height:150%\">
                    <span style=\"font-size: 12pt; line-height: 150%; font-family: Verdana, sans-serif; color: windowtext;\">
                        <!--<o:p>&nbsp;</o:p>-->
                    </span>
              </p>
              <table class=\"table\" border=\"2\" cellspacing=\"1\" cellpadding=\"1\" style=\"width: 940px;\" align=\"\">
                <tbody>
                    <tr>
                        <td style=\"text-align: center;\">
                            <span style=\"font-size: large; background-color: rgb(153, 153, 153);\">2. OBJETIVO</span>
                        </td>
                    </tr>
                </tbody>
              </table>";


$mpdf->WriteHTML($paragrafo);

$mpdf->Output();

exit;
?>
    
asked by anonymous 10.02.2016 / 01:58

1 answer

2

Your problem lies in using the border attribute in the table.

Unfortunately mpdf can not perform this simple conversion:

<table border="2">
// Para
<table style='border:2px solid black;'>

So he ends up ignoring this configuration.

Then you wonder, what are my alternatives?

1 - You can report to mpdf and wait for some possible correction.

2 - You can search for a text editor that delivers border code in css.

3 - Or you can do an advanced RTA, for example, if you know that all your tables will have borders you can add your css by customizing the mpdf.

Example:

$stylesheet = "table{
  width: 100%;
  text-align:center;
  border: 2px solid black;
}";

And then you add in WriteHTML like this:

$mpdf = new mPDF();
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);

Preview:

    
10.02.2016 / 20:31