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();
答案 0 :(得分:1)
你可以试试这个:
<?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();
?>