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 !

Laurent
  • 61
  • 1
  • 3

2 Answers2

6

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

options={'page-size':'A4', 'dpi':400}
Vladimir Vlasov
  • 1,860
  • 3
  • 25
  • 38
3

you can try to disable shrinking through the options as below

options = { 'disable-smart-shrinking': ''}
Hiran
  • 1,102
  • 11
  • 18