php实现pdf导出和打印功能。
2021-06-22 09:05
所用插件:TCODF
//导出pdf
public function export_pdf($order_sn){
require_once(FCPATH .‘../shared/plugin/tcpdf/tcpdf.php‘);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, "pt", "A4", true, ‘UTF-8‘, false);
$pdf->SetFooterMargin(50);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(FCPATH .‘../shared/plugin/tcpdf/examples/lang/eng.php‘)) {
require_once(FCPATH .‘../shared/plugin/tcpdf/examples/lang/eng.php‘);
$pdf->setLanguageArray($l);
}
$pdf->SetMargins(20,50,10 ,true);
$pdf->AddPage();
$pdf->SetFont(‘stsongstdlight‘, ‘‘, 12);
$buffer = $this->assign_value($order_sn);
$startpos = strpos($buffer,‘‘);
$endpos = strpos($buffer,‘‘);
$html = substr($buffer,$startpos,$endpos-$startpos+strlen(‘‘));
header("Content-type: text/html; charset=utf-8");
$name = "customs_declaration";
$export_name = $name.‘_‘.$order_sn;
$pdf->writeHTML($html,true,false,false,false,false);
$pdf->Output($export_name.‘.pdf‘, ‘d‘);
}
//将获取的网页赋值
public function assign_value($order_sn){
ob_start();
$this->declaration_print($order_sn);
$buffer = ob_get_contents();
ob_clean();
return $buffer;
}
通过ob缓存,将动态的页面缓存,已用来导出。
js打印