我在下面重现了我的问题:
我在网页上画了一个 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>
Run Code Online (Sandbox Code Playgroud)我使用 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)
Run Code Online (Sandbox Code Playgroud)我获得了一个 pdf 文件,左上角有一个矩形,其大小大约小了 5 倍......
如果您能看看,我将不胜感激!