Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf variable DPIs and page sizes in pixels

Tags:

wkhtmltopdf

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.

like image 559
Matt Harvey Avatar asked Feb 20 '14 01:02

Matt Harvey


People also ask

How do I change page size in Wkhtmltopdf?

Page sizes: The default page size of the rendered document is A4, but by using the --page-size option this can be changed to almost anything else, such as: A3, Letter and Legal. For a full list of supported pages sizes please see <https://doc.qt.io/archives/qt-4.8/qprinter.html#PaperSize-enum>.

How do I configure Wkhtmltopdf?

INSTRUCTIONS: Download an appropriate version of wkHTMLtoPDF library from http://wkhtmltopdf.org. If you are on Windows operating system then do install it under C:\ drive (for example c:\wkhtmltopdf). On Linux/UNIX, you can install it under /usr/local/bin and make sure wkhtmltopdf has execute permissions.


1 Answers

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

like image 67
Lipotam Avatar answered Nov 03 '22 23:11

Lipotam