Reputation: 1050
I'm trying to use TCPDF with laravel 4, I'm getting this error when I populate my table with mysql data, when I use the foreach loop it fails, if I remove it, it works just fine:
class PrintController extends BaseController {
public function index()
{
return View::make('print.PrintView');
}
public function generatePDF()
{
$notas_detalle = NotaDetalle::all();
$pdf = $pdf = new TCPDF();
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$html =
'<table border="1" cellpadding="4" cellspacing="0" align="center">
<thead>
<tr>
<th colspan="4">
<p>Chapincar S.R.L</p>
<p>Agustin Barios Nº 1070 c/ Julio C. Franco - Telefono 674 942 <br/>
Fernando de la Mora - Paraguay</p>
<p></p>
</th>
<th colspan="2">
<p>RUC:80029658-3</p>
<p>NOTA DE PRESUPUESTO</p>
</th>
</tr>
<tr>
<td colspan="6" align="left">Asuncion, 26 de Noviembre de 2014</td>
</tr>
<tr>
<td colspan="6" align="left">Señores: Aseguradora del Este</td>
</tr>
<tr>
<td colspan="6" align="left">Dirección: Gilberto Aranda 231</td>
</tr>
<tr>
<td colspan="2" align="left">Telefono: 021674611</td>
<td colspan="4" align="left">Fecha: 20/12/2014</td>
</tr>
</thead>
<tbody>
<tr>
<td>Cantidad</td>
<td colspan="3">Descripción</td>
<td>Precio con IVA</td>
<td>Precio sin IVA</td>
</tr>';
$html .= '<tr>';
// HERE IT'S THE ERROR
foreach ($notas_detalle as $key => $value) {
$html .= '<td>' . $value->cantidad_detalle . '</td>';
$html .= '<td colspan="3">' . $value->descripcion_detalle . '</td>';
$html .= '<td>' . $value->precioIVA_detalle . '</td>';
$html .= '<td>' . $value->precioSinIVA_detalle . '</td>';
}
// ERROR
$html .= '</tr>';
$html .=
'</tbody>
</table>'
;
$pdf->writeHTML($html, true, false, true, false, '');
//$pdf->Text(90, 140, 'This is a test');
$filename = storage_path() . '/test.pdf';
$pdf->output($filename, 'I');
//return Response::download($filename);
}
}
what I'm doing wrong?. Please help.
Upvotes: 1
Views: 190
Reputation: 4043
Solution was provided in the comments. Providing it here in case anyone else runs into a similar problem:
$html .= '<tr>';
and
$html .= '</tr>';
needed to be within the foreach loop
Upvotes: 0