【发布时间】:2017-10-08 23:49:09
【问题描述】:
我在下面重现了我的问题:
-
我在网页上画了一个 210x297 的矩形
<!DOCTYPE html> <html> <style> div.rectangle { border: solid 1px; width: 210mm; height: 297mm; } </style> <head> </head> <body> <div class="rectangle"> <img/> </div> </body> </html> -
我在 Python 中使用 pdfkit 将此 html 文档转换为 pdf
import pdfkit options = { 'page-size':'A4', 'encoding':'utf-8', 'margin-top':'0cm', 'margin-bottom':'0cm', 'margin-left':'0cm', 'margin-right':'0cm' } pdfkit.from_file('test.html', 'test.pdf', options=options) 我获得了一个 pdf 文件,其左上角有一个矩形,其大小大约小了 5 倍...
如果您能看一看,我将不胜感激!
【问题讨论】:
-
你有什么操作系统?我在 macOS 上遇到了同样的问题。
标签: python wkhtmltopdf pdfkit html-to-pdf python-pdfkit