Php 在Codeigniter上生成多页TCPDF
我有一个表,用于显示数据并基于每一行生成报告。该表如下所示:Php 在Codeigniter上生成多页TCPDF,php,codeigniter,tcpdf,Php,Codeigniter,Tcpdf,我有一个表,用于显示数据并基于每一行生成报告。该表如下所示: ----------------------------------------------------------------------------------------- | employee_name | division | period | allowance | download | checkbox | | tony | advertising | a
-----------------------------------------------------------------------------------------
| employee_name | division | period | allowance | download | checkbox |
| tony | advertising | august 2018| 15.00 |(downloadbtn)|(checkboxbtn)|
| lola | advertising | august 2018| 20.00 |(downloadbtn)|(checkboxbtn)|
-----------------------------------------------------------------------------------------
这是我目前生成pdf的控制器:
<?php
class AllowanceReport extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('allowance_m');
}
public function index(){
$this->load->view('allowance_v');
}
public function reportpdf($id){
ob_start();
$allowance= $this->allowance_m->get_allowance_byid($id);
$this->load->library('pdf_surat');
$pdf = new
PDF_SURAT('P','mm','A4',true,'UTF-8',false);
$pdf->AddPage();
$pdf->setXY(12,40);
$txt_pembuka = 'Allowance Report';
//$pdf->SetFontSize(16);
$pdf->SetFont('times', 'B', 16, '', 'false');
$pdf->MultiCell(0, 5, $txt_pembuka, 0, 'C', 0, 2, '', '', true);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->SetFont('times', '', 12, '', 'false');
$pdf->cell(35,5,"Nama");
$pdf->cell(0,5,": ".$allowance->employee_name);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->cell(35,5,"Periode");
$periode = strtotime($allowance->periode);
$formatperiode = date('F Y',$periode);
$pdf->cell(0,5,": ".$formatperiode);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->cell(35,5,"Uang Makan");
$pdf->cell(0,5,": Rp.".$allowance->allowance);
$pdf->Output();
ob_end_flush();
}
}
?>
我设法为每一行生成一个pdf。但是,是否可以根据选中的复选框生成包含多个页面的文件?pdf文件能否生成一个文件中使用不同页面检查的每个数据?您可以像下面这样做 前端 在表标记之前和之后添加表单标记,将表单目标设置为新方法(
allreportpdf
),并添加submit按钮以触发表单内部的save all report(可能在表单关闭标记之前):
后端
由于此页面使用不同的布局,您应该在AllowanceReport
类上使用以前设置的帖子名称(eid
)创建一个新方法,您可以在foreach()
循环中使用它,并修改pdf设置,以便在每个页面上分离每个id:
public function allreportpdf(){
ob_start();
$this->load->library('pdf_surat');
$pdf = new
PDF_SURAT('P','mm','A4',true,'UTF-8',false);
foreach ($this->input->post('eid') as $id) {
$allowance= $this->allowance_m->get_allowance_byid($id);
$pdf->AddPage();
$pdf->setXY(12,40);
$txt_pembuka = 'Allowance Report';
//$pdf->SetFontSize(16);
$pdf->SetFont('times', 'B', 16, '', 'false');
$pdf->MultiCell(0, 5, $txt_pembuka, 0, 'C', 0, 2, '', '', true);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->SetFont('times', '', 12, '', 'false');
$pdf->cell(35,5,"Nama");
$pdf->cell(0,5,": ".$allowance->employee_name);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->cell(35,5,"Periode");
$periode = strtotime($allowance->periode);
$formatperiode = date('F Y',$periode);
$pdf->cell(0,5,": ".$formatperiode);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->cell(35,5,"Uang Makan");
$pdf->cell(0,5,": Rp.".$allowance->allowance);
}
$pdf->output();
ob_end_flush();
}
已经试过了,但是上面写着:
Message:foreach()提供的参数无效
?确实需要您的帮助尝试在foreach之前添加这一行:print\r($this->input->post('eid');模具()代码>,那么输出是什么?它给了我26,最后一个选中行的id号我想我犯了一个错误,尝试在每个复选框输入名称后加上大括号,从name=“eid”
到name=“eid[]”
public function get_allowance_byid($id)
{
$sql = "SELECT * FROM allowance WHERE idallowance='".$id."'";
return $this->db->query($sql)->row();
}
<form action="<?php echo base_url() . "index.php/allowancereport/allreportpdf" ?>" method="POST" role="form">
<table class="table table-striped table-bordered table-hover">
...
...
...
</table>
<button type="submit" class="btn btn-primary">Get All Report</button>
</form>
<center>
<input type="checkbox" class="checkitem" name="eid[]" value="<?php echo $row->idmakan; ?>"/>
</center>
public function allreportpdf(){
ob_start();
$this->load->library('pdf_surat');
$pdf = new
PDF_SURAT('P','mm','A4',true,'UTF-8',false);
foreach ($this->input->post('eid') as $id) {
$allowance= $this->allowance_m->get_allowance_byid($id);
$pdf->AddPage();
$pdf->setXY(12,40);
$txt_pembuka = 'Allowance Report';
//$pdf->SetFontSize(16);
$pdf->SetFont('times', 'B', 16, '', 'false');
$pdf->MultiCell(0, 5, $txt_pembuka, 0, 'C', 0, 2, '', '', true);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->SetFont('times', '', 12, '', 'false');
$pdf->cell(35,5,"Nama");
$pdf->cell(0,5,": ".$allowance->employee_name);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->cell(35,5,"Periode");
$periode = strtotime($allowance->periode);
$formatperiode = date('F Y',$periode);
$pdf->cell(0,5,": ".$formatperiode);
$pdf->setXY(20,$pdf->getY()+7);
$pdf->cell(35,5,"Uang Makan");
$pdf->cell(0,5,": Rp.".$allowance->allowance);
}
$pdf->output();
ob_end_flush();
}