Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mPDF font-size not working for long text in a table

Tags:

font-size

mpdf

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.

like image 204
zef Avatar asked May 20 '14 12:05

zef


People also ask

How do I increase text size in TD tag?

You could add this code inline to the <table> tag, the <tr> tag or to each <th> tag. A few options but this is the code you need: style=font-size:12px, change 12 to whatever font size suits your needs.

How do I change font size in table tag?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size.

Which attribute can be used to change the size of the text?

In HTML, you can change the size of text with the <font> tag using the size attribute. The size attribute specifies how large a font will be displayed in either relative or absolute terms.


2 Answers

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.

like image 120
zef Avatar answered Oct 17 '22 08:10

zef


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

like image 4
Norlihazmey Ghazali Avatar answered Oct 17 '22 09:10

Norlihazmey Ghazali