Search code examples
pdfsymfony1cakephp-2.0symfony-1.4tcpdf

How to generate PDF using sfTCPDFPlugin in symfony 1.4?


I want to get a pdf of post details , so I installed sfTCPDFPlugin. I'm a new to it so can any one help me with this?

How to generate PDF using sfTCPDFPilugin in symfony 1.4?


Solution

  • The main problem you seems to have is to get the HTML output from your template to put it into the generated PDF. For that, you can use getPartial or getPresentationFor.

    I recommend you to use the getPartial. Create a partial with the content you want to extract (and by the way, you will be able to use the same partial elsewhere if you need the same information to be viewable as html).

    Assuming you create a partial called _my_partial.php, you can do that:

    public function executePdf()
    {
      $config = sfTCPDFPluginConfigHandler::loadConfig();
    
      /* put all your PDF configuration */
    
      $html = $this->getPartial(
        'my_partial', 
        // put in this array all variables you want to give to the partial
        array('posts' => $posts)
      );
    
      $pdf->writeHTMLCell(
        $w=0, 
        $h=0, 
        $x='', 
        $y='', 
        $html, 
        $border=0, 
        $ln=1, 
        $fill=0, 
        $reseth=true, 
        $align='', 
        $autopadding=true
      );
    
      $pdf->Output('example_001.pdf', 'I');
    
      throw new sfStopException();
    }