wkhtmltopdf variable DPIs and page sizes in pixels
Asked Answered
H

2

19

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.

Hannon answered 20/2, 2014 at 1:55 Comment(5)
Note: This appears to be a problem with wkhtmltopdf 0.12.0. I tries to same with 0.11.0 rc1 and it worked as I expected.Hannon
Are you running this on a Mac?Bultman
No. I have tested it on both Windows 7 and Debian though.Hannon
Everything looks right to me. You might have some luck posting to the Github project (there are a lot of Mac issues, that's why I asked). Maybe try 0.12.1 first in case it's already resolved though.Bultman
Did you solve it? I get the same results. if I set -zoom 0.319 the output is ok.Tanagra
E
10

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

Ellita answered 14/7, 2017 at 14:9 Comment(1)
Thanks for this approach. I had a layout computed upon a 96dpi resolution, correctly displaying wehen printing from browser but filling only ~80% of the page when using wkhtmltopdf. With the Zoom setting i was able to fill the page without compromising the layouting script.Tacmahack
H
0

As of wkhtmltopdf version 0.12.6, the CLI option of --dpi 600 works successfully.

(At least I had a DPI problem now, and specifying --dpi changed the document and solved the "pixelisation" problem for me.)

Humanitarian answered 11/12, 2021 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.