连接到$ pdf-> writeHTML?

时间:2014-09-01 01:03:21

标签: php html laravel tcpdf

我遇到了一些麻烦,想知道我在做什么甚至可能是我做的...

这是我的代码:

    public function pdf_post() {
        $pdf                 = new TCPDF();
        $clicked_serial = trim(Input::get('hidden_serial'));        
        $clicked_game   = Game::find($clicked_serial);  
        $site_name = $clicked_game->site->name;
        $game_name = $clicked_game->name;
        $in_play   = $clicked_game->in_datetime;
        $org_name  = Auth::user()->organization->name;

        $tbl = <<<EOD
            <style>
            table.org_info {
                border: 1px solid black;
                border-collapse: collapse;
            }
            </style>                    
            <table class="org_info" style="width:100%">
            <tr>
                <td>Organization Name: <u>$org_name</u><br></td>
                <td>Site Name: <u>$site_name</u><br></td>
            </tr>
            <tr>
                <td>Game Name: <u>$game_name</u><br></td> 
                <td>Serial Number: <u>$clicked_serial</u><br></td> 
            </tr>
            <tr>
                <td>Date put in play: <u>$in_play</u><br></td> 
                <td>Signature of person<br>putting game in play: ___________________________<br></td> 
            </tr>           
            </table>        
            <br><br>
            <table border="1">
                <thead>
                    <tr align="center">
                        <th>Date</th>
                        <th>Cash In</th>
                        <th>Funds Added/Removed</th>
                        <th>Cash Out</th>
                        <th>Notes</th>
                    </tr>       
                </thead>
            </table>
EOD;

        foreach (ShiftsGames::get() as $shiftgame) {
            $serial       = trim($shiftgame->serial);

            if ($serial == $clicked_serial) {
            $tbl .= <<<EOD
                <tbody>
                    <tr align="center">
                        <td>Test</td>
                        <td>Test</td>
                        <td>Test</td>
                        <td>Test</td>
                        <td>Test</td>
                    </tr>
                </tbody>
EOD;
            }
        }

        // create new PDF document
        $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

        // set document information

        $pdf->SetTitle('MINNESOTA LAWFUL GAMBLING');
        $pdf->SetSubject('LG861 Site Control/Tracking and Auditing of Paper Pull-Tab Game');

        // set default header data
        $pdf->SetHeaderData('', '', 'MINNESOTA LAWFUL GAMBLING', 'LG861 Site Control/Tracking and Auditing of Paper Pull-Tab Game');

        // set header and footer fonts
        $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

        // set default monospaced font
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

        // set margins
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

        // set auto page breaks
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

        // set font
        $pdf->SetFont('helvetica', 'B', 20);

        // add a page
        $pdf->AddPage();

        $pdf->Write(0, 'Game Information', '', 0, 'L', true, 0, false, false, 0);   

        $pdf->SetFont('helvetica', '', 10);

        $pdf->writeHTML($tbl, true, false, false, false, '');

        $filename = storage_path() . '/pdf/' . $clicked_serial . '.pdf';
        $pdf->output($filename, 'F');

        return Response::download($filename);
    }

我在laravel.log中收到错误: 2014-09-01 00:55:40] production.ERROR:异常'ErrorException',消息'未定义的索引:行'在/home/gmanager/laravel/vendor/tecnick.com/tcpdf/tcpdf.php:17045

如果我将$ tbl全部放在一个'EOD'中它会起作用,但是一旦我尝试连接就像我试图它不起作用。

任何人对我能做什么有任何想法?

1 个答案:

答案 0 :(得分:0)

哇!我刚刚做了简单的修复。

简单只需要向我添加第二个$ tbl

EX:

if ($serial == $clicked_serial) {
$tbl .= <<<EOD
<table border="1">
    <tbody>
        <tr align="center">
            <td>$date_time</td>
            <td>Test</td>
            <td>Test</td>
            <td>Test</td>
            <td>Test</td>
        </tr>
    </tbody>
</table>
EOD;