如何解决如何使用 Knp Snappy 包设置 pdf 的页面大小
我有一个代码,用于使用带有 Symfony2 的 KNP Snappy 捆绑包生成 PDF。这是它的样子:
$this->container->get('knp_snappy.pdf')->generateFromHtml(
$this->templating->render(
$twigInclude,array(,'htmlFiles' => $htmlFiles,'headlines' => $headlines,)
),$folderHistory . '/reports/' . $filename . '.pdf'
);
我的问题是,我想设置边距并将页面大小从 A4 更改为 A1。我找到了很多例子,但每次尝试时,pdf 似乎不再生成。我该如何解决这个问题并使其发挥作用。
预先感谢您的帮助。
解决方法
您可以在选项中设置几个标志:
$options = [
'page-size' => 'A1','margin-top' => 10,'margin-right' => 10,'margin-bottom' => 10,'margin-left' => 10,];
$this->container->get('knp_snappy.pdf')->generateFromHtml(
$this->templating->render(
$twigInclude,[
'htmlFiles' => $htmlFiles,'headlines' => $headlines,]
),$folderHistory . '/reports/' . $filename . '.pdf',$options,true // this flag will overwrite existing file
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。