// 打印预览
public function printExternal(Request $request){
//数据处理
$id = $request->id;
$data = PactContract::where(['id'=> $id])->with(['foreign','order'=>function($q){
$q->with(['client_dept']);
},'contract_list'=>function($q){
$q->with(['details']);
}])->first();
$arr = [];
foreach ($data->contract_list as $k => $v){
foreach ($v->details as $k3 => $v3){
$nations[] = $v3->nations->country_store->abbr;
}
$arr[$k]['total'] = $v->total;
$arr[$k]['price'] = $v->price;
$arr[$k]['total_sum'] = $v->total*$v->price;
$arr[$k]['nations'] = implode(',',$nations);
$arr[$k]['currency_abbr'] = account_type_v()[$data->currency];
}
$nalist = $arr;
// 或者是导出还是预览,1预览2导出
$pdf = new \TCPDF('P'); // L - 横向 P-竖向
// 设置文档信息
$foreign_name = foreign_trade()[$data->foreign->foreign_id]['name'];
$pdf->SetCreator($foreign_name);
$pdf->SetAuthor($foreign_name);
$pdf->SetTitle($foreign_name);
$pdf->SetSubject($foreign_name);
$pdf->SetKeywords('TCPDF, PDF, PHP');
// 设置页眉和页脚信息
// $pdf->SetHeaderData('tcpdf_logo.jpg', 30, 'XX公司', 'XX制造', [0, 64, 255], [0, 64, 128]);
$pdf->setFooterData([0, 64, 0], [0, 64, 128]);
// 设置页眉和页脚字体
$pdf->setHeaderFont(['stsongstdlight', '', '10']);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->setFooterFont(['helvetica', '', '8']);
// 设置默认等宽字体
$pdf->SetDefaultMonospacedFont('courier');
$pdf->setCellPaddings(10, 0, 10, 15);
// 设置间距
$pdf->SetMargins(10, 5, 10);//页面间隔
$pdf->SetHeaderMargin(0);//页眉top间隔
$pdf->SetFooterMargin(0);//页脚bottom间隔
// 设置分页
$pdf->SetAutoPageBreak(true, 25);
// set default font subsetting mode
$pdf->setFontSubsetting(true);
//设置字体 stsongstdlight支持中文
$pdf->SetFont('stsongstdlight', '', 10);
ob_clean();
//第一页 导出的页面
$view = \View::make("temp.contract.contract", ['data' => $data,'foreign_name'=>$foreign_name,'nalist'=>$nalist]);
$html = $view->render();
$html = preg_replace("/\s\s+/", '', $html);
$pdf->AddPage();
$pdf->writeHTML($html, true, false, true, false, true);
$pdfName = '成交确认书' . $data->order->order_no;
//输出PDF
$pdf->Output($pdfName . '.pdf', 'I');//I输出、D下载
// if ($type == 1) {
// $pdf->Output($pdfName . '.pdf', 'I');//I输出、D下载
// } else {
// $pdf->Output($pdfName . '.pdf', 'D');//I输出、D下载
// }
}
PHP打印预览PDF
猜你喜欢
转载自blog.csdn.net/xcbzsy/article/details/113110946
今日推荐
周排行