【问题标题】:Error Using TCPDF使用 TCPDF 时出错
【发布时间】:2014-12-22 04:06:50
【问题描述】:

我正在尝试将 TCPDF 与 laravel 4 一起使用,当我使用 mysql 数据填充表时出现此错误,当我使用 foreach 循环时它会失败,如果我删除它,它就可以正常工作:

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);
    }

}

我做错了什么?请帮忙。

【问题讨论】:

  • tcpdf 输出的错误是什么?您的 $notas_detalle 可能是空的,并且 tcpdf 不知道如何处理弹出的 PHP 错误而不是您期望的错误?
  • 这是 laravel 错误日志:codeshare.io/xvSvY 它不是空的,因为我用 isEmpty() if ($notas_detalle->isEmpty()) { echo '
    '; print_r($notas_detalle);回声'
    '; } 其他 { 回声 '
    ';回声“罪恶错误”;回声'
    '; }
  • 别忘了把 $html .= '' 和 $html .= '';在 foreach 循环中。
  • 是的!那个工作!!非常感谢!!这就是问题所在!

标签: php laravel-4 tcpdf


【解决方案1】:

在 cmets 中提供了解决方案。在这里提供它以防其他人遇到类似问题:

$html .= '<tr>';

$html .= '</tr>';

需要在 foreach 循环中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 2016-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多