2012-11-08 22 views
7

我使用Snappy Bundle以及Symfony 2.1。如何使用KnpSnappyBundle設置orientation = landscape?

我有一些問題,我沒有這個包的文檔中找到:

  • 如何設置的方向是什麼?
  • 有沒有辦法顯示頁碼?

這裏是我的包config.yml:

knp_snappy: 
    pdf: 
     enabled: true 
     binary:  /home/wkhtmltopdf-i386 
     options: [] 

這裏是我的控制器的一個生成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"')); 

} 

非常感謝您的幫助!

回答

15
$pdf = $this->get('knp_snappy.pdf')->getOutputFromHtml($html, 
            array('orientation'=>'Landscape', 
             'default-header'=>true)); 
+0

謝謝您的回答,但我有錯誤不起作用「致命錯誤:調用未定義的方法KNP \包\ SnappyBundle \斯納皮\ LoggableGenerator ::的SetOption()」 – Reveclair

+0

我想你的代碼,同時也$ 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」'));但這不起作用:( – Reveclair

+3

你已經把參數放在錯誤的位置,它應該看起來像這樣:'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」')));' –