利用php实现html转pdf,支持图片,css样,汉字和英文,,pdf文件下载,专用于个人信息导出 public function export_pdf(){set_time_limit(120);vendor("tcpdf.tcpdf");require_cache(VENDOR_PATH . 'tcpdf/examples/lang/e
public function export_pdf(){
set_time_limit(120);
vendor("tcpdf.tcpdf");
require_cache(VENDOR_PATH . 'tcpdf/examples/lang/eng.php');
$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// 设置文档信息
$pdf->SetCreator('author');
$pdf->SetAuthor('author');
$pdf->SetTitle('Welcome');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, PHP');
// 设置页眉和页脚信息
$pdf->SetHeaderData('', 30, 'baidu.com', '技术在中国',
array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// 设置页眉和页脚字体
$pdf->setHeaderFont(Array('stsongstdlight', '', '10'));
$pdf->setFooterFont(Array('helvetica', '', '8'));
// 设置默认等宽字体
$pdf->SetDefaultMonospacedFont('courier');
// 设置间距
$pdf->SetMargins(15, 27, 15);
$pdf->SetHeaderMargin(5);
$pdf->SetFooterMargin(10);
// 设置分页
$pdf->SetAutoPageBreak(TRUE, 25);
// set image scale factor
$pdf->setImageScale(1.25);
// set default font subsetting mode
$pdf->setFontSubsetting(true);
//设置字体
$pdf->SetFont('stsongstdlight', '', 14);
$pdf->AddPage();
// create some HTML content
$html ='
';
// output the HTML content
$pdf->writeHTML($html, true, 0, true, 0);
// reset pointer to the last page
$pdf->lastPage();
//Close and output PDF document
$pdf->Output('example_021.pdf', 'I');
// $showType= 'D';//PDF输出的方式。I,在浏览器中打开;D,以文件形式下载;F,保存到服务器中;S,以字符串形式输出;E:以邮件的附件输出。
// $pdf->Output("{$fileName}.pdf", $showType);
}
样图.png
