问题
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