無法設定 wkhtmltopdf 頁邊距(頂部和底部)

無法設定 wkhtmltopdf 頁邊距(頂部和底部)

我在 Ubuntu 上使用 wkhtmltopdf 0.10.0 rc2 (Linux 3.2.0-24-generic #38-Ubuntu x86_64 GNU/Linux)。我遇到的問題是我無法建立具有頂部邊距或底部邊距的 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 或頁面並不重要。如何設定 margin-top 和 margin-bottom?

答案1

我相信你缺少單位。嘗試:

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

mm當然是毫米。你也可以做 0.5 英寸或 2 厘米,類似的東西。

答案2

我在這裡超級晚了,但我遇到了類似的問題(我不斷更改邊距但沒有效果),經過大量工作後我找到了我的問題:我的內容由於尺寸有限,所以邊距並不重要。

我使用 Bootstrap 3 為我的 PDF 建立佈局,在 Bootstrap 中我有一個<div class="container">元素包裹整個頁面。 Bootstrap 中的容器周圍有自然的填充,因此我的內容只有 668 像素寬(儘管 wkHTMLtoPDF 在 800 像素寬的瀏覽器中加載頁面)。當我用<div class="container-fluid">邊距替換它時突然開始工作

只是值得檢查的東西

答案3

使用 wkhtmltopdf 0.12.6,wkhtmltopdf 0.10.0 rc2 不相容

相關內容