如何生成pdf,老是报错 [ 2.0 版本 ]
最近项目中要把页面直接生成pdf,老是出错,有什么好的栗子可以参考
共 3 个回答
-
public function outreport($result){ ob_start(); // Include the main TCPDF library (search for installation path). vendor('Pdf.tcpdf'); //实例化 $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // 设置文档信息 $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 001'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // 设置页眉和页脚信息 $pdf->SetHeaderData('', '', '电脑人机工程评估报告', '', array(0,64,255), array(0,64,128)); $pdf->setFooterData(array(0,64,0), array(0,64,128)); // 设置页眉和页脚字体 $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // 设置默认等宽字体 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // 设置间距 $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // 设置分页 $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l); } // --------------------------------------------------------- // set default font subsetting mode $pdf->setFontSubsetting(true); //设置字体 $pdf->SetFont('dejavusans', '', 14, '', true); $pdf->SetFont('stsongstdlight', '', 10); // Add a page // This method has several options, check the source code documentation for more information. $pdf->AddPage(); // set text shadow effect $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal')); // 内容 $html =$result['report']; // Print text using writeHTMLCell() $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); // --------------------------------------------------------- // Close and output PDF document // This method has several options, check the source code documentation for more information. $dtime = date('Y-m-d'); $pdf->Output($dtime.'.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+ } }
共 3 条回复 -
-
vipdhf
注册时间:2016-04-06
最后登录:2018-12-06
在线时长:21小时7分
最后登录:2018-12-06
在线时长:21小时7分
- 粉丝2
- 金钱100
- 威望10
- 积分410