wkhtmltopdf not rendering percentage widths correctly

倾然丶 夕夏残阳落幕 提交于 2019-12-12 03:52:59

问题


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%.

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

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%;
}

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?


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/41333817/wkhtmltopdf-not-rendering-percentage-widths-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!