title: Symfony 1.4 with TCPDF: How to retrieve data from a database and show it as a .pdf file?
body: <p>I work with Symfony 1.4. I want to create a pdf file using TCPDF with the content of a query involving multiple tables.
  Here my code in the actions.class.php:</p>
  
  <pre><code>public function executeTest()
  { 
       $this-&gt;conflictos1s = Doctrine_Core::getTable('Conflictos1')
        -&gt;createQuery('a') 
        -&gt;leftJoin('a.SectorActividadCiuTa7')     
        -&gt;leftJoin('a.RelacionConflictualPrincipalTa9') 
        -&gt;leftJoin('a.SubsectorActividadTa8')       
         -&gt;leftJoin('a.DemandasTa2')      
         -&gt;leftJoin('a.ActoresTa1')     
         -&gt;leftJoin('a.Conflictos1HasActoresTa1')    
        -&gt;orderBy('a.Id DESC')
              -&gt;execute();  
  
    $config = sfTCPDFPluginConfigHandler::loadConfig();
  
    // pdf object
    $pdf = new sfTCPDF();
  
    // set document information
    $pdf-&gt;SetCreator(PDF_CREATOR);
    $pdf-&gt;SetAuthor('J. H.');
    $pdf-&gt;SetTitle('TCPDF Example 001');
    $pdf-&gt;SetSubject('TCPDF Tutorial');
    $pdf-&gt;SetKeywords('TCPDF, PDF, example, test, guide');
  
    // set default header data
   $pdf-&gt;SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING);
  
    // set header and footer fonts
    $pdf-&gt;setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf-&gt;setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  
    // set default monospaced font
    $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  
    //set margins
    $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);
  
    //set auto page breaks
    $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  
    //set image scale factor
    $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  
    // ---------------------------------------------------------
  
    // set default font subsetting mode
    $pdf-&gt;setFontSubsetting(true);
  
    // Set font
    // dejavusans is a UTF-8 Unicode font, if you only need to
    // print standard ASCII chars, you can use core fonts like
    // helvetica or times to reduce file size.
    $pdf-&gt;SetFont('dejavusans', '', 10);
  
    // Add a page
    // This method has several options, check the source code documentation for more information.
  
  $pdf-&gt;AddPage();
  
  $pdf-&gt;Write(0, '', '', 0, 'L', true, 0, false, false, 0);
  
  $pdf-&gt;SetFont('helvetica', '', 6);
    // Set some content to print
   $html = $this-&gt;getPartial(
      'generar_pdf', 
      // put in this array all variables you want to give to the partial
  
     array('posts' =&gt; $posts)
    );
    $pdf-&gt;writeHTML($html, true, false, false, false, '');
  
    // ---------------------------------------------------------
  
    // Close and output PDF document
    // This method has several options, check the source code documentation for more information.
    $pdf-&gt;Output('example_conflictos.pdf', 'I');
  
    // Stop symfony process
    throw new sfStopException();
  }
  </code></pre>
  
  <p>Here my template code (a partial called _generar_pdf.php). I have followed the advice here:
  <a href="https://stackoverflow.com/questions/8153305/using-php-with-tcpdf-to-retreive-datausing-mysql-from-a-database-and-show-it-a/8153558#8153558">Using PHP with TCPDF to retrieve data(using mysql) from a database and show it as a .pdf file</a></p>
  
  <pre><code>&lt;?php ob_start(); ?&gt;
  &lt;h2&gt;Listado de Conflictos&lt;/h2&gt;
  &lt;table cellspacing="1" border="1"&gt;       
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Id&lt;/th&gt;
         &lt;th&gt;Ver acciones&lt;br&gt;conflictivas&lt;/th&gt;
        &lt;th&gt;Ver actores&lt;/th&gt;
         &lt;th&gt;Fecha comienzo&lt;/th&gt;
        &lt;th&gt;Relacion conflictual principal&lt;/th&gt;
        &lt;th&gt;Sector actividad&lt;/th&gt;
        &lt;th&gt;Subsector actividad&lt;/th&gt;
        &lt;th&gt;Demandas&lt;/th&gt;      
        &lt;th&gt;Descripcion-general&lt;/th&gt;
        &lt;th&gt;Descripcion protagonista&lt;/th&gt;
        &lt;th&gt;Descripcion antagonista&lt;/th&gt;
        &lt;th&gt;Descripcion demandaprinc&lt;/th&gt;
        &lt;th&gt;Nivel estado&lt;/th&gt;
        &lt;th&gt;Descripcion sector&lt;/th&gt;
        &lt;th&gt;Fecha final&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;?php foreach ($conflictos1s as $conflictos1): ?&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getId() ?&gt;&lt;/a&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo date('d/m/Y', strtotime($conflictos1-&gt;getFechaComienzo())) ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getRelacionConflictualPrincipalTa9() ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getSectorActividadCiuTa7() ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getSubsectorActividadTa8() ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getDemandasTa2() ?&gt;&lt;/td&gt;
         &lt;td width="20%"&gt;&lt;?php echo substr($conflictos1-&gt;getDescripcionGeneral(),0,60) ?&gt;&lt;/td&gt; 
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getDescripcionProtagonista() ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getDescripcionAntagonista() ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getDescripcionDemandaprinc() ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getNivelEstado() ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $conflictos1-&gt;getDescripcionSector() ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php if(!is_null($conflictos1-&gt;getFechaFinal())){ echo date('d/m/Y', strtotime($conflictos1-&gt;getFechaFinal()));} ?&gt;&lt;/td&gt; 
      &lt;/tr&gt;
      &lt;?php endforeach; ?&gt;      
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;?php $posts = ob_get_contents();
  ob_end_clean(); 
  echo $posts ?&gt;
  </code></pre>
  
  <p>Here my result:
  <img src="https://i.stack.imgur.com/RH8wO.jpg" alt="PDF file">
  I can not see the variable data. What am I doing wrong?</p>