Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdf page margins with snappy and symfony2

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.

like image 238
GatorGuy023 Avatar asked Mar 14 '16 18:03

GatorGuy023


1 Answers

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.

like image 114
chalasr Avatar answered Nov 11 '22 08:11

chalasr