修复了在Codefniter中使用FPDF以Pdf格式打印时每页的行数

时间:2018-01-23 12:00:12

标签: php codeigniter-3 fpdf

我有一张表,其中有31条记录。当我点击PDF格式上显示的打印按钮数据时很好。但是默认情况下每页有16行。我想每个显示10行。如何我这样做。我是codeigniter和FPDF的新手。请有人帮助我,先谢谢。

这是我的以pdf格式打印数据的功能

function viewdata($result){
if(isset($result)){
foreach($result as $values){
  $this->SetFont('Arial','',10.5);
  $this->Cell(60,10,$values['vndr_name'],1,0,'L');
  $this->Cell(90,10,$values['vndr_address'].','.$values['state'].'-'.$values['vndr_pincode'],1,0,'L');
  $this->Cell(50,10,$values['vndr_telephone'].','.$values['vndr_mobile'],1,0,'L');
  $this->Cell(70,10,$values['vndr_mailid'],1,0,'L');
  $this->ln();
}
}
}

$this->pdf = new Printview();
$this->pdf->SetMargins(15, 10, 20);
$this->pdf->AliasNbPages();
$this->pdf->AddPage('L','A4',0);
$this->pdf->viewdata($result);
$this->pdf->Output();

这是我的控制器代码

public function printpage(){
   $this->load->library('fpdf/fpdf');
   $data['result']=$this->Vendor_Model->displaydata();
   if(!empty(array_filter($data))){
   $this->load->view('printview',$data);
  }
  else{
    redirect('Vendorcontroller/showeditview');
    }

}

1 个答案:

答案 0 :(得分:0)

您可以通过附加AddPage()方法在每10行拆分页面:

function viewdata($result){
    if(isset($result)){
        $total_row = count($result); // get the total row
        $i = 0;
        foreach($result as $values){
            $this->SetFont('Arial','',10.5);
            $this->Cell(60,10,$values['vndr_name'],1,0,'L');
            $this->Cell(90,10,$values['vndr_address'].','.$values['state'].'-'.$values['vndr_pincode'],1,0,'L');
            $this->Cell(50,10,$values['vndr_telephone'].','.$values['vndr_mobile'],1,0,'L');
            $this->Cell(70,10,$values['vndr_mailid'],1,0,'L');
            $this->ln();
            if (++$i % 10 == 0 && $i != $total_row) { // add a page break on every 10 row & prevent adding an extra page if it is the last row
                $this->AddPage('L','A4',0);
            }
        }
    }
}