php生成pdf并保存到服务器

 1         $data = input('post.');
 2         
 3         require_once '../extend/tcpdf/tcpdf.php';
 4 
 5         //新建一个PDF文档
 6         $pdf = new \TCPDF('P', 'mm', 'A4', true, 'UTF-8', false, false);
 7         // 关闭页眉
 8         $pdf->setPrintHeader(false);
 9         // 关闭页脚
10         $pdf->setPrintFooter(false);
11         $pdf->AddPage();
12         $pdf->SetFont('stsongstdlight', '', 14); // 使用中文字体,不设置这个,中文就会乱码
13         //如果要对html指定 宽度  writeHTMLCell更方便
14         // html table表格识别更准确  css必须使用行内样式
15         $html = html_entity_decode($data['html']);
16         
17         $pdf->writeHTMLCell(0, 0, 0, 0, $html, 0, 0, 0, true, '', true);
18         
19         //输出PDF 
20         
21         ob_clean();
22         $pdf->Output($_SERVER['DOCUMENT_ROOT'] .'/uploads/pdf/'.$data['id'].'.pdf', 'F'); 24         return json(['code'=>1,'msg'=>'录入成功','data'=>'/uploads/pdf/'.$data['id'].'.pdf']);
25         exit();

 

posted @ 2022-04-18 15:41  桓台彭于晏  阅读(409)  评论(0)    收藏  举报