How to set orientation = landscape using KnpSnappyBundle?
11,820
$pdf = $this->get('knp_snappy.pdf')->getOutputFromHtml($html,
array('orientation'=>'Landscape',
'default-header'=>true));
Author by
Reveclair
Updated on July 28, 2022Comments
-
Reveclair almost 2 years
I'm using Snappy Bundle along with Symfony 2.1.
I have some question I did not find in the documentation of this bundle :
- How to set the orientation ?
- Is there a way to display page numbers ?
Here is my config.yml for the bundle :
knp_snappy: pdf: enabled: true binary: /home/wkhtmltopdf-i386 options: []
Here is one of my Controller to generate a pdf :
public function exampleAction() { $html = $this->renderView('MyBundle:Example:test.pdf.twig', $this->param); return new Response($this->get('knp_snappy.pdf')->getOutputFromHtml($html),200, array( 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="Test.pdf"')); }
Thanks a lot for your help!
-
Reveclair over 11 yearsThanks for your answer but that does not work as I have the error "Fatal error: Call to undefined method Knp\Bundle\SnappyBundle\Snappy\LoggableGenerator::setOption()"
-
Reveclair over 11 yearsI tried your code and also $pdf = ($this->get('knp_snappy.pdf')->getOutputFromHtml($html), 200, array('orientation'=>'Landscape', 'default-header'=>true,'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="Test.pdf"')); But that does not work :(
-
james_t over 11 yearsYou've put the parameters in the wrong location, it should look like this:
return new Response($this->get('knp_snappy.pdf')->getOutputFromHtml($html, array('orientation'=>'Landscape', 'default-header'=>true)), 200, array('Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="Test.pdf"')));
-
user1383418 over 10 yearsYou know what would really be nice? A link to some documentation. I don't see any reference to an 'orientation' option in the Snappy README ~ github.com/KnpLabs/KnpSnappyBundle/blob/master/README.markdown
-
userfuser about 10 yearsKNP Snappy is actually a wrapper for a WKHTMLTOPDF shell utility. Here is a link to its manual: wkhtmltopdf.org/usage/wkhtmltopdf.txt and you will find "orientation" and all other options in it.
-
famas23 over 3 yearsif you have one document with 2 pages: first page is Landscape and the other one is portrait! How I can do it?