小编Lau*_*ent的帖子

pdfkit - A4 html 页面无法打印成 A4 pdf

我在下面重现了我的问题:

  1. 我在网页上画了一个 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)
  2. 我使用 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)
  3. 我获得了一个 pdf 文件,左上角有一个矩形,其大小大约小了 5 倍......

如果您能看看,我将不胜感激!

python pdfkit html-to-pdf wkhtmltopdf python-pdfkit

5
推荐指数
1
解决办法
7310
查看次数

标签 统计

html-to-pdf ×1

pdfkit ×1

python ×1

python-pdfkit ×1

wkhtmltopdf ×1