问题描述
我正在尝试开发一个可以生成 pdf 的网页.我想知道是否有办法使用 KnpSnappyBundle for symfony2 自定义 pdf 的页边距.我对此进行了粗略搜索,但找不到任何信息.任何信息都非常感谢.
I am trying to develop a web page that will generate a pdf. I was wondering if there is a way to customize the page margins of the pdf using KnpSnappyBundle for symfony2. I did a cursory search for this and couldn't find any information. Any information is greatly appreciated.
推荐答案
您可以将选项作为每个生成方法的第二个参数传递:
You can pass options as the second argument of each generating method :
$snappy = $this->get('knp_snappy.pdf');
$options = [
'margin-top' => 50,
'margin-right' => 50,
'margin-bottom' => 50,
'margin-left' => 50,
];
$snappy->getOutputFromHtml($html, $options);
或者使用 setOption
:
foreach ($options as $margin => $value) {
$snappy->setOption($margin, $value);
}
$snappy->getOutputFromHtml($html, $options);
查看整个knp_snappy.pdf
class 和 可用 wkhtmltopdf选项.
请注意,如果您是从 HTML 生成 PDF,则应在使用 wkhtmltopdf 选项之前尝试使用 CSS 设置页边距.
Note that if you are generating PDF from HTML, you should try to use CSS for your margins before use wkhtmltopdf options.
这篇关于带有 snappy 和 symfony2 的 pdf 页边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!