Overdose
Overdose

Reputation: 585

Problem with wkhtmltopdf or css size (A4, mm, in)

I'm using wkhtmltopdf through the Symfony Bundle knp Snappy bundle and it works fine as long as I'm using px for size. But I need to generate a sticker sheet based on A4 size and I can't have anything right : I set all margin to 0 for wkhtmltopdf

$snappy->setOption('margin-top', '0mm');
$snappy->setOption('margin-left', '0mm');
$snappy->setOption('margin-right', '0mm');
$snappy->setOption('margin-bottom', '0mm');

then in my test html (it's a twig in the application) for a columns: i've tried a simple :

<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="utf-8">
</head>
<body style="margin:0;padding:0">
  <div style="background-color:red;width:99%;height:1400px;border:solid #000 1px">
    <div style="background-color:green;display:inline-block;padding:0;margin:0;width:105mm;height:297mm"></div>
    <div style="background-color:yellow;display:inline-block;padding:0;margin:0;width:105mm;height:297mm"></div>
  </div>
</body>
</html>

i've also tried with inches : 105 => 4.13in, 297mm => 11.69in with the same result

I've also tried to generate directly (without the bundle)

wkhtmltopdf --page-size A4 -B 0 -L 0 -R 0 -T 0 test.html output.pdf

with the same result

This is what i get : enter image description here

why half the A4 size: 105mm or 4.13in is not working? I've also tried setting directly the page size in the wkhtmltopdf setup : page-height and page-width with no change.

I can't use percentages because with the real data I will have more complex settings (margin left and right, 2, 3... columns)

What could be wrong about the setup? is it a CSS problem ? a wkhtmltopdf problem?

Upvotes: 2

Views: 6345

Answers (1)

Overdose
Overdose

Reputation: 585

I found out that using the --disable-smart-shrinking option helped a lot. By default the --enable-smart-shrinking is activated and messes with the html rendering, when using absolute measures (in, mm) link to doc

Upvotes: 9

Related Questions