doudun8705 2014-12-21 15:42
浏览 161
已采纳

使用TCPDF时出错

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.

  • 写回答

1条回答 默认 最新

  • dongliao1948 2014-12-21 20:06
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂