wkhtmltopdf 未正确呈现百分比宽度 [英] wkhtmltopdf not rendering percentage widths correctly

查看:59
本文介绍了wkhtmltopdf 未正确呈现百分比宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 wkhtmltopdf 从引导程序布局生成 PDF,在大多数情况下,结果非常接近浏览器呈现的结果.但是,我注意到使用分段的引导行"(由许多 col-xs 组成)使得总宽度加起来不会达到 100%.

I am using wkhtmltopdf to generate PDFs from bootstrap layouts, for the most part, the results are very close to what is rendered by the browser. However, I noticed that using segmented "bootstrap rows" (composed by many col-xs) makes so the total width does not add up to 100%.

我在文档的一部分中使用了 12 col-xs-1,结果可以在这里看到:

I am using 12 col-xs-1 in one part of the document, and the result can be seen here:

这是列类的 CSS(或者至少是我尝试更改的部分):

Here is the CSS for the class of the columns (or at least the part I tried to change):

.col-xs-1 {
    float: left;
    width: 8.333333%;
}

我将宽度 % 增加到 8.37% 并且没有任何变化,大小保持不变.但是,当我将其增加到 8.38% 时,它太大并且会破坏布局(最后一列转到下一行).

I increased the width % up to 8.37% and nothing changes, the size remains the same. But, when I increase it to 8.38%, then it`s too large and breaks the layout (the last column go to the next line).

再次,在浏览器中它看起来不错.在我看来,有一个舍入错误或与列的宽度混淆的东西.当你有边框时,它变得非常明显.

Again, in the browser it looks good. It seems to me that there is a rounding error or something that is messing with the widths of the columns. It becomes very obvious when you have borders.

有人对我应该尝试什么有任何建议吗?

Does anyone have any suggestion on what should I try?

推荐答案

好的,那么问题是 wkhtmltopdf 不渲染十进制像素 (10.5px = 10px ...)

Ok, so the problem is that wkhtmltopdf does not render decimal pixels (10.5px = 10px ...)

问题的修复"是增加 dpi 设置.我把它设置为2000 dpi,最终文件大小和处理时间保持不变,同时解决了问题.可能有我现在不知道的副作用,但到目前为止,它似乎对我正在做的事情工作正常.

A "fix" for the problem was to increase the dpi setting. I set it to 2000 dpi, and the final file size and processing time remained the same, while solving the problem. There could be a side effect that I am not aware right now, but so far it seems to work fine for what I am doing.

另一个解决方法是确保 100% 的宽度是 12(或您正在使用的 N 列)的倍数.我没有测试过,但似乎合乎逻辑.

Another fix could be to make sure that the 100% width is a number multiple of 12 (or N columns you are using). I did not test that, but seems logical.

无论如何,在这里记录以希望能帮助遇到同样问题的人.

Anyways, documenting here to hopefully help someone with the same problem.

这篇关于wkhtmltopdf 未正确呈现百分比宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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