准备工作简介TCPDF说明文档<?php
require_once('tcpdf.php');
?><?php
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
?>以下是使用TCPDF的示例,做法很简单,看代码吧<?php
/**
* Created by ZhengNiu.
* User: 77103
* Date: 2019/5/17
* Time: 10:40
*/
require_once './tcpdf/Tcpdf/tcpdf.php';
$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('ZhengNiu');
$pdf->SetTitle('Welcome to NiuZhengBlog!');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, PHP');
// set default header data
$pdf->SetHeaderData('./touxiang.png', 30, 'Welcome to NiuZhengBlog', '测试', array(0,64,255), array(0,64,128));
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
global $l;
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('simfang', '', 14);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Print a table
// add a page
$pdf->AddPage();
// 随便写HTML
$html = '人呢,可贵之处在于能抓住自己喜欢的人,喜欢的事物,并为之努力,而不是总重复感叹,循环遗憾,后悔是常态,但不是最好的状态。不是每个人都会主动跟你开口的,小孩子才会等待别人来哄你来爱你,成年人只会争取自己想要的爱情。';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();
$pdf->Output('test.pdf', 'I');可以不断添加addPage,添加多页,最后Output输出自己的名字的文件即可。可以看到其中可以插入图片也是没有问题的,写法就按照html写就OK,当然不只是支持HTML,只是这里比较适合这种方式。
以上附资源下载 链接:微云密码:zt8be0