KnpSnappyBundle页眉和页脚不显示

时间:2018-09-30 16:24:21

标签: symfony symfony-3.4 knp-snappy

正如标题所述,我无法使用knp_snappy.pdf可视化页脚和页眉,我看到了几个示例,但没有一个对我有用,我得到了pdf,但页脚和页眉却没有,我不知道是配置问题或其他问题,下面的此链接有效,但其他链接有效,但在我的代码中无效。 我正在使用symfony 3.4,“ knplabs / knp-snappy-bundle”:“ ^ 1.5”和wkhtmltopdf-0.12.2.4

示例:
https://github.com/KnpLabs/KnpSnappyBundle/issues/195
https://github.com/KnpLabs/KnpSnappyBundle/issues/154

这是我的代码:
config.yml

        "1": {
        "id":"1",
        "year": "1969 (The Jackson 5)",
        "name": "Diana Ross Presents The Jackson 5",
        "numberofsongs": "12"
    },

    "2": {
        "id":"2",
        "year": "1970 (The Jackson 5)",
        "name": "ABC",
        "numberofsongs": "12"
    }
}
}

pdf / report.html.twig

knp_snappy:
pdf:
    enabled:    true
    binary:     /usr/bin/xvfb-run /usr/bin/wkhtmltopdf
    options:    []

pdf / footer.html.twig

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>My PDF</title>
</head>
<body>
<h1>My PDF</h1>
<p>Harum trium sententiarum nulli prorsus assentior.</p>
<h1>My PDF</h1>
</body>
</html>

控制器

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Contrat Thuasne Services</title>
  <script>
    /* page counter */
    function subst() {
      var vars={};
      var x=document.location.search.substring(1).split('&');
      for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
      var x=['topage','page'];
      for (var i in x) {
        var y = document.getElementsByClassName(x[i]);
        for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
      }
    }
  </script>
</head>
<body onload="subst()">
<footer>
  <table>
    <tr>
      <td style="width: 33%;">Test</td>
      <td style="width: 34%;" class="center"><span class="page"></span>/<span class="topage"></span></td>
      <td style="width: 33%;" class="right">&copy; Society {{ "now"|date("Y") }}</td>
    </tr>
  </table>
</footer>
</body>
</html>

我不知道出什么问题了,谢谢!!

0 个答案:

没有答案