Pdfkit - A4 html page does not print in A4 pdf format

I reproduced my problem below:

  • I am drawing a 210x297 rectangle on a webpage

    <!DOCTYPE html>
    <html>
    <style>
    div.rectangle {
      border: solid 1px;
      width: 210mm;
      height: 297mm;
    }
    </style>
    <head>
    </head> 
    <body> 
    <div class="rectangle">
      <img/>
    </div>
    </body>
    </html>
    
          

  • I am converting this html document to pdf using 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)
    
          

  • I am getting a pdf with a rectangle in the upper left corner, which is about 5 times smaller ...

I would really appreciate it if you could take a look!

+3


source to share


2 answers


For me, manually adjusting DPI works as a workaround:



options={'page-size':'A4', 'dpi':400}

      

+2


source


you can try to disable compression via options like below



options = { 'disable-smart-shrinking': ''}

      

0


source







All Articles