wkhtmltopdf保持字体大小问题 [英] wkhtmltopdf keep font size issue

查看:206
本文介绍了wkhtmltopdf保持字体大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用wkhtmltopdf 0.12.1.2将html文件转换为pdf,并且输出的字体大小不同,字体大小为13.68,但在html中为11pt.有任何帮助使其匹配吗?

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.

推荐答案

此问题是由QT在html解析期间引起的.这也取决于所使用的字体.如果我们提取字体样式并检查字体大小,则可以对大小从点到像素的转换有所了解.当我在Explorer/Google Chrome浏览器中检查点到像素的转换时,像素值未如下所示.通过在PDF转换时从wkhtmltopdf运行JavaScript来检索以下值.

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.

对于Arial,下面给出的是转换.

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

然后,为了将它们转换为所需的大小,我写了另一种方法,用上述像素值替换上面的像素值列表,该像素值在PDF中提供了预期的输出.Arial字体的转换如下所示:

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

这解决了我的问题,并给出了与PDF完全匹配的字体.

This solved my issue and gave the exact matching font in PDF.

这篇关于wkhtmltopdf保持字体大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆