Reputation: 185
I'm converting a html file to pdf with wkhtmltopdf 0.12.1.2 and the font sizes are different on the output, the font size is 13.68 but it's 11pt in the html. Any help on getting it to match?
<span style="font-family: Calibri; font-size: 11pt; ">
<table>
<tbody>
<tr><td>this is a test Calibri 11pt font</td></tr>
etc etc
wkhtmltopdf32.exe --disable-smart-shrinking --page-width 215.900000 --page-height 279.400000 1.htm 1.pdf
even if I remove the page size it's still the same.
Upvotes: 2
Views: 6538
Reputation: 1892
I had an issue these days and the only thing that helped me fix the font-size was adding this in command line, after reading all default options used by wkhtmltopdf.
--disable-smart-shrinking
By default is ON, and it does this (as per documetation)
Enable the intelligent shrinking strategy used by WebKit that makes the pixel/dpi ratio non-constant (default)
By the way, if you use a common headder, things such as font-size, font-family, must be declared in that header.
Upvotes: 1
Reputation: 323
This issue is caused during the html parsing by QT. It depends also on the font used. If we extract the font style and check the size of font, we can get some idea about the conversion of size from point to pixels. When I checked the conversion of point to pixel in Explorer/Google Chrome the pixel value is not as shown below. Below values are retrieved by running a JavaScript from wkhtmltopdf in the time of PDF conversion.
In case of Arial the below given is the conversion.
8pt -> 10px
9pt -> 12px
10pt -> 13px
11pt -> 14px
12pt -> 16px
14pt -> 18px
16pt -> 21px
18pt -> 24px
20pt -> 26px
22pt -> 29px
24pt -> 32px
26pt -> 34px
28pt -> 37px
36pt -> 48px
48pt -> 64px
72pt -> 96px
Then, to convert them to the required size, I wrote another method to replace the above list of pixel values by the pixel values that gives the expected output in PDF. The conversion for Arial font was like shown below :
10px -> 11.5px
12px -> 13.5px
13px -> 14.5px
14px -> 15.95px
16px -> 17px
18px -> 20px
21px -> 23.5px
24px -> 26.25px
26px -> 28.5px
29px -> 31.5px
32px -> 34.5px
34px -> 37.5px
37px -> 40.5px
48px -> 51.75px
64px -> 69px
96px -> 104px
This solved my issue and gave the exact matching font in PDF.
Upvotes: 2