【问题标题】:Problem with wkhtmltopdf or css size (A4, mm, in)wkhtmltopdf 或 css 大小(A4,毫米,英寸)的问题
【发布时间】:2019-03-09 11:37:12
【问题描述】:

我通过 Symfony Bundle knp Snappy bundle 使用 wkhtmltopdf,只要我使用 px 作为大小,它就可以正常工作。 但我需要根据 A4 尺寸生成一张贴纸,但我什么都做不好: 我将 wkhtmltopdf 的所有边距设置为 0

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

然后在我的测试 html 中(它是应用程序中的一个树枝)中的列: 我试过一个简单的:

<!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>

我也试过英寸:105 => 4.13in, 297mm => 11.69in 结果一样

我也尝试过直接生成(不使用捆绑包)

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

结果一样

这就是我得到的:

为什么一半的 A4 尺寸:105 毫米或 4.13 英寸不起作用? 我还尝试在 wkhtmltopdf 设置中直接设置页面大小: page-height 和 page-width 没有变化。

我不能使用百分比,因为对于真实数据,我会有更复杂的设置(左右边距、2、3...列)

设置可能有什么问题? 是 CSS 问题吗? wkhtmltopdf 的问题?

【问题讨论】:

    标签: css wkhtmltopdf


    【解决方案1】:

    我发现使用--disable-smart-shrinking 选项有很大帮助。 默认情况下,--enable-smart-shrinking 被激活并与 html 渲染混淆,当使用绝对度量(in,mm)时 link to doc

    【讨论】:

    • 也解决了我的问题,谢谢。还要确保缩放没有设置为其他值,默认为 1。'zoom' =&gt; 1, 'disable-smart-shrinking' =&gt; true,
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-03
    相关资源
    最近更新 更多