如何使用laravel将表内容分成thujohn pdf上的第二页

时间:2015-07-22 06:11:57

标签: php laravel pdf

我有一个大型单个pdf文档,其中包含多个记录。我需要使用laravel将表记录拆分或拆分为pdf中的第二页。

使用控制器中的以下编码,表格记录未完全显示。该pdf文件中缺少一些表格记录。因此我需要将缺失的表格记录显示在pdf文件的第二个页面中。

    private function generatePdf($customerstatement, $content) {

    if (!is_dir(RECEIPTS_DIR)){
        mkdir(RECEIPTS_DIR, 0755, true);
    }        
    $outputName = $customerstatement->card_id . '-' . strtoupper(date("MY"))   .'.pdf';
    $pdfFileName = RECEIPTS_DIR.'/' . $outputName;
    $view =  View::make("admin.document.statement", compact('customerstatement', 'content'))->render();
    $pdf = new \Thujohn\Pdf\Pdf();
    $bytes_written = File::put($pdfFileName, $pdf->load($view, 'A4', 'portrait')->output());
    if ($bytes_written === false) {
        throw new \Exception("Unable to produce pdf statement");
    }
    $customerstatement->pdffile = $outputName;
    $customerstatement->save();
    return $outputName;  
}   

以下编码写在刀片文件中,用于显示pdf中的记录。

 <tbody> 
  <tr>
       <td colspan="7"><b>{{ $customerstatement->customer->card_id }} - {{ $customerstatement->customer->fullName }} </b>
       </td>
  </tr>
  <tr>
       <td colspan="7"><b>Beginning Balance : {{ $customerstatement->beginning_balance }}</b>
       </td>
  </tr>


   @foreach ($customerstatement->statements as $statement)
                <tr>
                    <td width="7em">{{{ $statement->date }}}</td>
                    <td width="15em">{{{ $statement->memo }}}</td>
                    <td width="6em" align="center">{{{ $statement->debit }}}</td>
                    <td width="6em" align="center">{{{ $statement->credit}}}</td>
                    <td width="6em" align="center">{{{ $statement->closing_balance}}}</td>                          
                </tr>
    @endforeach

   </tbody>

1 个答案:

答案 0 :(得分:0)

       <tr>
       <td colspan="7"><b>
            {{ $customerstatement->customer->card_id }} - {{ $customerstatement->customer->fullName }} </b></td>
        </tr>
        <tr><td colspan="7"><b>Beginning Balance : {{ $customerstatement->beginning_balance }}</b></td></tr>
               <?php $i=0 ?>
                @foreach ($customerstatement->statements as $statement)
                <?php $i++ ?>
               <tr>
                   <td width="7em">{{{ date("d-m-Y", strtotime($statement->date) )}}}</td>
                   <td width="15em">{{{ $statement->memo }}}</td>
                   <td width="6em" align="center">{{{ $statement->debit }}}</td>
                   <td width="6em" align="center">{{{ $statement->credit}}}</td>
                   <td width="6em" align="center">{{{ $statement->closing_balance}}}</td>    
                   <td ><?php
                           if($i==25){ ?>
                           <?php $i=0 ?>
                               <div style="page-break-after: always;"></div>  
                        <?php   }
                    ?></td>
               </tr>