php - SetAutoPageBreak 不起作用或者我没有正确使用它

标签 php mysql tcpdf fpdf

SetAutoPageBreak 不起作用或者我没有正确使用它。它会在页脚之前停止第一页,但之后的每一页都只打印一行,再打印 39 页。我做错了什么。我找不到有关添加更多信息以使其正常工作的更多信息。这是一个链接http://notaryaccounting.com/doc-2.pdf到输出文件,这样你就可以看到

class PDF extends tcpdf
{
// Page header
    function Header()
    {
        $this->SetFont('dejavusans', 'BI', 20, '', 'false');
        $this->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
        // Move to the right
        $this->Ln(5);
        $this->Cell(60);
        $this->Cell($w, $h=0, $txt='INCOME REPORT', $border=0, $ln=0, $align='', $fill=false, $link='', $stretch=0,
            $ignore_min_height=false, $calign='T', $valign='M');
        $this->Line (0, 13, 210, 13, $style=array());
        // Line break
        $this->Ln(5);
    }
// Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        // Page number
        $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }

}
$pdf = new PDF();
$pdf->AddPage();

$pdf->SetAutoPageBreak(TRUE,20);
$pdf->SetFont('arial','B',12);

$y_axis = 20;
//Set Row Height
$row_height = 6;
//Go to next row
$y_axis = $y_axis + $row_height;
//initialize counter
$pageLine = 0;
//Set maximum rows per page
$itemsPerPage = 5;

$result = $db->query("Select
  customers.name,
  signings1.signstart,
  signings1.fname,
  signings1.lname,
  signings1.city,
  signings1.state,
  signings1.samount,
  signings1.prtamount,
  signings1.faxamount
From
  customers Inner Join
  signings1 On customers.custid = signings1.custid
Where
  signings1.pid = 6 And
  signings1.done = 1
Order By
  customers.name ,
  signings1.signstart ");
$current=null;
foreach($result as $key => $income) {


    if($current!=$income['name']){

        $pdf->SetY($y_axis);
        $pdf->SetFillColor(0,68,150);
        $pdf->SetTextColor (252,252,252);
        $pdf->SetX(05);
        $pdf->Cell(200,6,'Customer:' . '               ' . $income['name'] ,1,0,'L',1);

        //print column titles for the current page
        $y_axis = $y_axis + 6;
        $pdf->SetY($y_axis);
        $pdf->SetFillColor(0,68,120);
        $pdf->SetTextColor (252,252,252);
        $pdf->SetX(05);
        $pdf->Cell(30,6,'Date:',1,0,'L',1);
        $pdf->Cell(70,6,'Name:',1,0,'L',1);
        $pdf->Cell(70,6,'Location:',1,0,'L',1);
        $pdf->Cell(30,6,'Amount:',1,0,'L',1);
        $current = $income['name'];


 }
    $y_axis = $y_axis + $row_height;
    $pdf->SetY($y_axis);
    $pdf->SetX(05);
    $pdf->SetTextColor (0,0,0);
    $total = $income['samount'] + $income['prtamount'] + $income['faxamount'];
    $name = $income['fname'] . ' ' .$income['lname'];
    $signdate=phpdate($income['signstart']);
    $pdf->Cell(30,6,$signdate,1,0,'L',0);
    //$pdf->Cell(10,6,$income['custid'],1,0,'L',0);
    $pdf->Cell(70,6,$name,1,0,'L',0);
    $pdf->Cell(70,6,$income['city'],1,0,'L',0);
    $pdf->Cell(30,6,$total,1,0,'L',0);

} 

$pdf->Output();

最佳答案

你可以试试这个:

<?php

require ('fpdf.php');

class PDF extends FPDF
{
// Page header
    function Header()
    {
        $this->SetFont('Arial', 'BI', 20);
        $this->Ln(5);
        $this->Cell(60);
        $this->Cell(190,10,'INCOME REPORT','B',1,'C',0);
        // Line break
        $this->Ln(5);
    }
// Page footer
    function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
        // Page number
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}','T',0,'C',0);
    }

}

$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();

$pdf->SetFont('arial','B',12);

$result = $db->query("Select
  customers.name,
  signings1.signstart,
  signings1.fname,
  signings1.lname,
  signings1.city,
  signings1.state,
  signings1.samount,
  signings1.prtamount,
  signings1.faxamount
From
  customers Inner Join
  signings1 On customers.custid = signings1.custid
Where
  signings1.pid = 6 And
  signings1.done = 1
Order By
  customers.name ,
  signings1.signstart ");
$current=null;
foreach($result as $key => $income) {


    if($current!=$income['name']){ /* PROCEED WHEN THE LAST NAME IS NOT THE SAME WITH THE CURRENT NAME */

        $pdf->SetFillColor(0,68,150);
        $pdf->SetTextColor (252,252,252);

        $pdf->Cell(200,6,'Customer:' . '               ' . $income['name'] ,1,1,'L',1);

        //print column titles for the current page

        $pdf->SetFillColor(0,68,120);
        $pdf->SetTextColor (252,252,252);

        $pdf->Cell(30,6,'Date:',1,0,'L',1);
        $pdf->Cell(70,6,'Name:',1,0,'L',1);
        $pdf->Cell(70,6,'Location:',1,0,'L',1);
        $pdf->Cell(30,6,'Amount:',1,1,'L',1);
        $current = $income['name'];


    } /* END OF IF, LAST NAME IS NOT THE SAME WITH THE CURRENT NAME */

    $pdf->SetTextColor (0,0,0);
    $total = $income['samount'] + $income['prtamount'] + $income['faxamount'];
    $name = $income['fname'] . ' ' .$income['lname'];
    $signdate=phpdate($income['signstart']);

    $pdf->Cell(30,6,$signdate,1,0,'L',0);
    $pdf->Cell(70,6,$name,1,0,'L',0);
    $pdf->Cell(70,6,$income['city'],1,0,'L',0);
    $pdf->Cell(30,6,$total,1,1,'L',0);

} /* END OF  FOREACH */

$pdf->Output();

?>

关于php - SetAutoPageBreak 不起作用或者我没有正确使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23463135/

相关文章:

php - 向 php $_POST 发送 cURL 终端命令返回 null

PHP 从不带键/值对的 URL 查询字符串中获取值

java - 如何处理DataIntegrityViolationException以获取具体原因?

php - 使用命名占位符设置 PDO/MySQL LIMIT

mysql - sql中两个表的列求和

PHP While 循环仅显示最后一行

php - 使用 TCPDF 的多行文本?

php - MySQL 触发器到 PostgreSql 触发器的转换

php - 用于 PHP 的 L-Soft LISTSERV TCPGUI 界面

php - 除页码外,删除 tcpdf 中的底线