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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With