drbae3964 2014-05-05 00:20
浏览 90
已采纳

SetAutoPageBreak不工作或我没有正确使用它

SetAutoPageBreak not working or I am not using it correctly. It stops the first page just before the footer but then every page after that just print one line for 39 more pages.What am I doing wrong with this. I can not find anymore information about adding more info to make it work correctly. Here is a link http://notaryaccounting.com/doc-2.pdf to the output file so you can see

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();
  • 写回答

1条回答 默认 最新

  • dsf11t5u1651 2014-05-05 03:06
    关注

    You can try this:

    <?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();
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件