mpdf和dompdf,mPDF中动态生成的页面的页码

I am using mPDF with Codeigniter for creating PDF files. I have a problem when adding page number.

I have some result sets that are generated via database queries and I pass them to my html file to display that data. According to the number of results it creates and converts to pdf format with number of pages. Problem is I cannot add page numbers when it generates more than one page.

I am using the basic examples for this operation.

Please help me on this!

My controller code

$result_1 = $this->Vessel_model->getManifestVesselDetails($vesselId,$containerId);

$result_2 = $this->Vessel_model->getVesselDetailsByContainer($vesselId,$containerId);

$result_3 = $this->Vessel_model->getDDByVesselContainer($vesselId,$containerId);

$data['agentDetails'] = $this->Vessel_model->getShippingAgents();

$data['DD_SDNumber'] = $this->DD_SDNumber;

$data['DDdetails'] = $result_3;

$data['containerDetails'] = $result_2;

$data['vesselcontainerDetails'] = $result_1;

$html = $this->load->view('reports/tri_shipping_manifest_PDF', $data, true);

//this the the PDF filename that user will get to download

$pdfFilePath = APPPATH.'/'.date('Y-m-d').$result_1->vessel.'-'.$result_1->serialno.".pdf";

$pdfFilePath3 = date('Y-m-d').$result_1->vessel.'-'.$result_1->serialno.".pdf";

$this->load->library('pdfreports');

$this->pdf = $this->pdfreports->load();

//$this->pdf->setFooter('{PAGENO}');

$this->pdf->AddPage('L','',1,'i','on');

$this->pdf->WriteHTML($html,0);

$this->pdf->Output($pdfFilePath3, "D");

$this->pdf->Output($pdfFilePath, "F");

解决方案

I don't know how current code should look like, because i don't know much about mPDF, but i would suggest you to use domPdf with Codeigniter, because is much simpler then this library.

You can find domPdf here

Since we don't know what is the output for those variables and what should be printed in pdf, i can only suggest some generally code created with domPdf

create helper:

function pdf_create($html, $filename='', $stream=TRUE){

require_once("dompdf/dompdf_config.inc.php");

$dompdf = new DOMPDF();

$dompdf->load_html($html);

$dompdf->render();

$dompdf->set_paper("A4");

if ($stream) {

$dompdf->stream($filename.".pdf",1);

} else {

return $dompdf->output();

}

}

?>

create controller for pdf

$data['store']=$res;

$this->load->helper(array('dompdf', 'file'));

$html = $this->load->view('store/sales_pdf', $data, true);

$html.= $this->load->view('footer');

$filename="salesbill".$id;

pdf_create($html, $filename);

$data = pdf_create($html, '', false);

write_file('name', $data);

?>

And your pdf HTML would look something like this

@page { margin: 180px 50px; }

#header { position: fixed; left: 0px; top: -180px; right: 0px; height: 150px; background-color: orange; text-align: center; }

#footer { position: fixed; left: 0px; bottom: -180px; right: 0px; height: 150px; background-color: lightblue; }

#footer .page:after { content: counter(page, upper-roman); }

the first page

the second page

This answer is based on this stackoverflow question

Also here is nice domPdf debug helper page

I hope this answer helps you out

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值