问题描述
我通过 Symfony Bundle
为什么 A4 尺寸的一半:105 毫米或 4.13 英寸不起作用?我也试过在 wkhtmltopdf 设置中直接设置页面大小:页面高度和页面宽度没有变化.
我不能使用百分比,因为对于真实数据,我会有更复杂的设置(左右边距,2、3...列)
设置可能有什么问题?这是一个CSS问题吗?wkhtmltopdf 问题?
我发现使用 --disable-smart-shrinking
选项有很大帮助.默认情况下,--enable-smart-shrinking
被激活并与 html 渲染混淆,当使用绝对度量(in,mm)文档链接
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.69inwith 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 :
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?
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
这篇关于wkhtmltopdf 或 css 尺寸问题(A4、mm、in)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!