pdfkit - An A4 html page does not print into an A4 pdf
Asked Answered
T

2

6

I have reproduced my problem below :

  1. I draw a 210x297 rectangle on a web page

    <!DOCTYPE html>
    <html>
    <style>
    div.rectangle {
      border: solid 1px;
      width: 210mm;
      height: 297mm;
    }
    </style>
    <head>
    </head> 
    <body> 
    <div class="rectangle">
      <img/>
    </div>
    </body>
    </html>
    
  2. I transform this html document to pdf with pdfkit in Python

    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)
    
  3. I obtain a pdf file with a rectangle at the top left corner whose size is roughly 5 times too small...

I would really appreciate if you can have a look !

Tical answered 10/5, 2017 at 11:3 Comment(1)
What OS do you have? I have the same issue on the macOS.Jugate
J
6

For me manual set up of the DPI works as workaround:

options={'page-size':'A4', 'dpi':400}
Jugate answered 26/5, 2017 at 18:43 Comment(0)
A
4

you can try to disable shrinking through the options as below

options = { 'disable-smart-shrinking': ''}
Alexis answered 21/5, 2019 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.