无法设置wkhtmltopdf边距(顶部和底部)


5

我在Ubuntu(Linux 3.2.0-24-generic#38-Ubuntu x86_64 GNU / Linux)上使用wkhtmltopdf 0.10.0 rc2。我遇到的问题是我无法创建具有顶部或底部空白的PDF。我没有任何错误。

我正在使用以下命令:

wkhtmltopdf -T 50 -B 50 http://google.com ./test.pdf
wkhtmltopdf --margin-top 50 --margin-bottom 50 page.html ./test.pdf

但是,当我尝试以下操作时,margin-left和margin-right效果很好(但仍然没有margin-top或margin-bottom)

wkhtmltopdf -L 50 -R 50 -T 50 -B 50 page.html ./test.pdf

我尝试转换哪个URL或页面都没有关系。如何设置页边距上限和页底距?

linux  ubuntu  pdf 

Answers:


11

我相信您缺少单位。尝试:

wkhtmltopdf -L 50mm -R 50mm -T 50mm -B 50mm page.html ./test.pdf

毫米,当然是毫米。您也可以做0.5英寸或2厘米之类的东西。


“ mm”和“ cm”单位有效,但“ in”单位似乎被忽略。(我在Win64上使用0.12.1-rc。)
user326177 2014年

1

我在这里迟到了,但是遇到了一个类似的问题(我一直在更改边距以至没有效果),经过大量工作,我发现了我的问题:我的内容大小有限,因此边距没有物。

我使用Bootstrap 3为PDF创建布局,在Bootstrap中,我有一个<div class="container">元素包装了整个页面。Bootstrap中的容器周围有自然填充,因此我的内容只有668像素宽(尽管wkHTMLtoPDF在800像素宽的浏览器中加载了页面)。当我将其替换为<div class="container-fluid">边距时,突然开始工作

只是值得检查的东西


我认为这是一个有用的答案。只是为将来的读者提供一个注释,该答案中提到的课程是特定于Bootstrap的,因此里程可能会有所不同。
Joundill
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.