12

Using mPDF to print html to pdf the font-size I set in html is not properly set in creating the pdf. In my html I have

<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-family:myriadpro, Verdana, sans-serif; color:#111111;">
<tr>
<td align="left" style="vertical-align:top; padding:5px; font-size: 12pt;">
etc.

However mPDF scales the font-size to 9pt in the PDF. If I use 24pt it scales to 18pt. I checked and tried to change the configs and displaypreferences (NoPrintScaling) in mPDF but none of this is working.

Has anybody got a clue on how to get rid of this scaling? I don´t want to set the font-size bigger to compensate for mPDF behaviour because that will ruin my html view.

Finwe
  • 6,372
  • 2
  • 29
  • 44
zef
  • 649
  • 1
  • 7
  • 22

3 Answers3

15

mPDF uses autosizing tables and this influences, among other things, the font-size as well. When outputting tables with mPDF you need to set:

<table style="overflow: wrap">

on every table. See Auto-layout algorithm in the mPDF manual for reference.

zef
  • 649
  • 1
  • 7
  • 22
  • That link does not exists now – Amar Singh Jun 28 '16 at 08:21
  • 2
    @Yo Yo. The original mPDF manual apparantly is not online anymore but a copy is made available on github. I have changed the link accordingly. – zef Jun 28 '16 at 12:22
  • @zef Link links to the manual but it does not work with 'wrap' for me, but with 'hidden' it does. Thanks – mimros Apr 24 '19 at 15:53
  • And, I forgot, it didn't work as a style defined directly in tab html element, but it worked since I add 'overflow:hidden' to default styles to a table style generated in Html() class which is Mpdf class inherits from. I guess that same procedure is for external style file ... – mimros Apr 25 '19 at 07:30
4

If anyone still got the same issue after tested with accepted answer, try this :

<table style="overflow: wrap" autosize="1">

And

$mPdf->shrink_tables_to_fit = 1;

Hope this helped as my case was solved only with these combination

Norlihazmey Ghazali
  • 9,000
  • 1
  • 23
  • 40
0

overflow: wrap and autosize="1" is not working for me , I also tried to replace the shrink_tables_to_fit => 1 in config.php(ConfigVariables.php) I followed the div style and it worked , however I do have a problem with the borders when the content is too long

poorIT
  • 1
  • 1