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