如何在laravel TCPDF中获取表字段的逐页总计?

时间:2018-07-13 11:39:02

标签: php laravel tcpdf

我正在使用tcpdf在laravel项目中以pdf格式查看数据。 (我只是附上了示例pdf屏幕截图)。

我总共有14条记录,当我在tcpdf中打印它们时,得到的记录分为两页,如下所示。

第1页:

Page1

第2页:

Page2

在第一张图片的最后一行显示了第11条记录。

但是我希望它显示我当前页面的总分。我期望的PDF格式如下所述。

预期的第1页:

enter image description here

预期的第2页:

enter image description here

如何在tcpdf中实现呢? 还是在laravel中有其他选择?

我尝试过的代码:

 PDF::SetTitle('MultiSessionSummary');
   PDF::setHeaderCallback(function($pdf){
        $headertext = '<div style="text-align: center;">
        <h1 style="margin: 0;">Header</h1>
        </div>';
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP+15, PDF_MARGIN_RIGHT);
        $pdf->SetFont('helvetica', 'I', 10);
        $pdf->writeHTML($headertext, false, true, false, true);
        $pdf->Cell(35,0, '', 0, false, 'C', 0, '', 0, false, 'T', 'M');
    });
    PDF::setFooterCallback(function($pdf){
        $footertext = "Version 0.1".date('Y-m-d H:i:s');
        $pdf->SetY(200);
        $pdf->SetFont('helvetica', 'I', 10);
        $pdf->writeHTML($footertext, false, true, false, true);
        $pdf->Cell(35,0, 'Page '.$pdf->getAliasNumPage().'/'.$pdf->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    });
PDF::Cell(30, 6, 'Deposits', 1, 0, 'L', 1);
        PDF::AddPage('L', 'A4');
        PDF::writeHTMLCell($w=0, $h=0, $x=5, $y=20, $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
        PDF::Output('multi_session_summary.pdf');

我的刀片:

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Hello World</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
    <script src="main.js"></script>
</head>
<body>

<div style="text-align: center;">
<h2>Games Report From {{$fromDate}} To {{$toDate}}<br>
Report Generated On {{date('Y-m-d H:i:s')}}</h2>
</div>
<div style="margin:0px;">
<table border="1">
  @if(COUNT($multiSessionSummary)!=0)
    <tr nobr="true">
      <th style="width:2%;text-align:center;">#</th>
      <th style="width:9%;text-align:center;">Bingo<br>Date</th> 
      <th style="width:8%;text-align:center;">Starting<br>Bank</th>
      <th style="width:8%;text-align:center;">Fill<br>Amount</th>
      <th style="text-align:center;">Drop<br>Amount</th> 
      <th style="width:10%;text-align:center;">Available Bal<br>(Liability)</th>
      <th style="text-align:center;">Deposits</th>
      <th style="text-align:center;">Total<br>Balance</th>
      <th style="text-align:center;">Player<br>Spend</th>
      <th style="width:9%;text-align:center;">Withdrawals</th>
      <th style="text-align:center;">Expected<br>Cash</th>
      <th style="text-align:center;">Total<br>Ante</th>
      <th style="width:10%;text-align:center;">Total Balance Remaining<br>(Liability)</th>
    </tr>
    @foreach($multiSessionSummary as $summaryDetails)
      <tr nobr="true">
        <td style="width:2%;text-align:center;">{{$index++}}</td>
        <td style="width:9%;text-align:center;">{{$summaryDetails->BingoDate}}</td>
        <td style="width:8%;text-align:right;">${{$summaryDetails->StartingBank}}</td>
        <td style="width:8%;text-align:right;">${{$summaryDetails->FillAmount}}</td>
        <td style="text-align:right;">${{$summaryDetails->DropAmount}}</td>
        <td style="width:10%;text-align:right;">${{$summaryDetails->AvailibleBalance}}</td>
        <td style="text-align:right;">${{$summaryDetails->Deposits}}</td>
        <td style="text-align:right;">${{$summaryDetails->TotalBalance}}</td>
        <td style="text-align:right;">${{$summaryDetails->PlayerSpend}}</td>
        <td style="width:9%;text-align:right;">${{$summaryDetails->Withdrawals}}</td>
        <td style="text-align:right;">${{$summaryDetails->ExpectedCash}}</td>
        <td style="text-align:right;">${{$summaryDetails->Ante}}</td>
        <td style="width:10%;text-align:right;">${{$summaryDetails->TotalBalanceRemaining}}</td>
      </tr>
    @endforeach
  @endif
</table>
</div>
</body>
</html>

0 个答案:

没有答案