pdf page margins with snappy and symfony2

让人想犯罪 __ 提交于 2019-12-14 01:12:35

问题


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.


回答1:


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);

Or use setOption :

foreach ($options as $margin => $value) {
    $snappy->setOption($margin, $value);
}

$snappy->getOutputFromHtml($html, $options);

See the whole knp_snappy.pdf class and available wkhtmltopdf options.

Note that if you are generating PDF from HTML, you should try to use CSS for your margins before use wkhtmltopdf options.



来源:https://stackoverflow.com/questions/35995847/pdf-page-margins-with-snappy-and-symfony2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!