wkhtmltopdf variable DPIs and page sizes in pixels

Matt Harvey picture Matt Harvey · Feb 20, 2014 · Viewed 17.9k times · Source

I am trying to test out a simple page that I wish to use to generate an A4 PDF at 300 DPI. Which I calculated to be 2480px wide and 3507px high;

This is the HTML which I expected to create a single page PDF that has a red border around the edges. The problem is that I am getting PDF that is four pages long.

<html>
    <head>
        <style>
            body {
                margin: 0;
                padding: 0;
                width:2480px;
                height:3507px;
            }
        </style>
    </head>
    <body>
        <div style="width:2480px; height:3507px; border:1px solid red;"/>
    </body>
</html>

This is the command I am using to generate the PDF:

wkhtmltopdf --disable-smart-shrinking --page-size A4 --dpi 300 --margin-bottom 0 --margin-left 0 --margin-right 0 --margin-top 0 test.html test.pdf

I can't work out if I am doing something wrong, such as missing a setting or calculating the size of my page incorrectly?

Any help would be appreciated.

Answer

Lipotam picture Lipotam · Jul 14, 2017

dpi is not working in wkhtmltopdf version 0.12.4

the default value is 96. Try to use zoom setting with value 96/300 = 0.32