4

I am building a mPDF code with information fetched from the database.

When the user inserts too much text, when it's printed in the mPDF, the size of the text becomes realy small. I want the text to have the same size as the rest of the document in the PDF.

Here's my code:

$mpdf->AddPage();
$mpdf->WriteHTML("<h1>Habilitações Literárias</h1>");
$mpdf->WriteHTML("<br>");

$query2=mysql_query("SELECT * from hl where id_user='$idd'" );
$row2 = array();

while ($data2 = mysql_fetch_array($query2)) {
    $row2[] = $data2; 
}

foreach ($row2 as $x2) {
    $dataa2 = $x2[0];
    $instituicao = $x2[1];
    $descricao2 = $x2[2];
    $mpdf->WriteHTML("<table border='0' width='100%'>");
    $mpdf->WriteHTML("<tr><td><b>Instituição:</b> $instituicao</td> <td><b>Data:</b> $dataa2 </td></tr>   ");
    $mpdf->WriteHTML("<tr><td><b>Descrição:</b> $descricao2 </td></tr>");
    $mpdf->WriteHTML("</table>");
    $mpdf->WriteHTML("<hr>");
}

Here is a link of an image with the example: https://i.stack.imgur.com/UrNOs.png

As you can see, the text is really small on the last record, because the "Descricao" field is very large.

Finwe
  • 6,372
  • 2
  • 29
  • 44
armandomaria
  • 99
  • 1
  • 2
  • 13
  • 1
    Just for your information, we can fix this issue in another way also. I too faced same problem when a table tr have very big content. I tried this option - $mpdf->shrink_tables_to_fit=0 which is not helped for me. What I did, I changed the html structure from table into div and the problem fixed now. It may help some one. Thanks for posting this issue. – Manikandan S Apr 27 '17 at 12:01
  • mine using this http://stackoverflow.com/questions/23760018/mpdf-font-size-not-working/43996204#43996204 – Norlihazmey Ghazali May 16 '17 at 08:42

2 Answers2

4

I just fixed similar problem, with style="overflow:wrap" after reading the source code:

elseif ($table['overflow']=='wrap')
  • You should avoid editing the source code directly if you dont want to loose your changes on library update. I did the same by changing the CSS inside html code with the style tag `table {overflow:wrap }` – BoCyrill Sep 23 '20 at 07:37
2

mPDF automatically reduces font size in tables. There is a maximum shrink factor set in $this->shrink_tables_to_fit variable in config.php. It can be turned off / set differently with

$mpdf->shrink_tables_to_fit=0

in config.php or with providing an extra parameter to the opening table tag:

<table autosize="1">

Default value for the variable is 1.4.

Also see mPDF manual on tables.

Finwe
  • 6,372
  • 2
  • 29
  • 44