TCPDF说明文档

TCPDF说明文档

一、首先调用TCPDF文件

require_once('tcpdf.php');

二、实例化TCPDF类 页面方向(P =肖像,L =景观)、测量(mm)、页面格式

 $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); 

三、设置文档信息

设置文档信息----文件创作者

$pdf->SetCreator('Helloweba');

$pdf->SetAuthor('yueguangguang');

$pdf->SetTitle('Welcome to helloweba.com!');

$pdf->SetSubject('TCPDF Tutorial');

$pdf->SetKeywords('TCPDF, PDF, PHP');

 

四、设置默认标题数据

    

  $pdf->SetHeaderData(PDF_HEADER_LOGO,PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 038', PDF_HEADER_STRING);

五、设置页眉和页脚信息

$pdf->SetHeaderData('./logo.jpg', 30, 'Helloweba.com', '致力于WEB前端技术在中国的应用', array(0,64,255), array(0,64,128));

$pdf->setFooterData(array(0,64,0), array(0,64,128));
  1. 设置页眉和页脚字体
$pdf->setHeaderFont(Array('stsongstdlight', '', '10'));

$pdf->setFooterFont(Array('helvetica', '', '8'));
  1. 设置默认等宽字体
$pdf->SetDefaultMonospacedFont('courier');

八、设置默认等宽字体

$pdf->SetDefaultMonospacedFont('courier');

九、设置间距

$pdf->SetMargins(15, 27, 15);

$pdf->SetHeaderMargin(5);

$pdf->SetFooterMargin(10); 

十、设置分页

$pdf->SetAutoPageBreak(TRUE, 25);

十一、设置自动换页

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

十二、设置图像比例因子

$pdf->setImageScale(1.25);

十三、设置默认字体构造子集模式

$pdf->setFontSubsetting(true);

十四、设置字体

$pdf->SetFont('stsongstdlight', '', 12);

十五、添加一个页面

$pdf->AddPage();

 

十六、该方法从当前位置打印文本

      (行高,文本变量,通过AddLink()返回的URL或标识符,背景画,允许中心或对齐文本,如果正确设置光标底部的线,否则设置游标的行,字体延伸模式,如果真的只打印第一行并返回剩余的字符串,如果真正的字符串是一行的开始,最大高度,补白)

     $pdf->Write(0,$str1,'', 0, 'L', true, 0, false, false, 0);

 

十七、安全密码设置

$user_pass用户密码、$owner_pass 所有者密码、$mode加密强度0 = RC4 40位;1 = RC4 128位;2 = AES 128位;3 = AES 256位。、 $pubkeys数组包含公钥证书(“c”)的接受者和权限(“p”)$pdffile['password']

$pdf->SetProtection($permissions = array('print', 'modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-high'), $user_pass = '123456', $owner_pass = null, $mode = 0, $pubkeys = null );

 

十八、输出PDF

 默认是I:在浏览器中打开,D:下载,F:在服务器生成pdf ,S:只返回pdf的字符串,个人感觉无实在意义

$pdf->Output('t.pdf', 'I');

 

扩展--输入文字:

单行文本
Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0)
Cell(宽, 高, 内容, 边框, 是否换行, 文字对齐, 文字底色,连接, 变宽)

多行文本
MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)
MultiCell(宽, 高, 内容, 边框,文字对齐, 文字底色, 是否换行, x坐标, y坐标, 变高, 变宽, 是否支持html, 自动填充, 最大高度)

html文字

setHtmlLinksStyle($color=array(0,0,255), $fontstyle='U');
setHtmlLinksStyle(颜色默认蓝色, U有下划线);
addHtmlLink($url, $name, $fill=0, $firstline=false, $color='', $style=-1);
addHtmlLink(超链接地址, 显示文字, 是否有底色, $firstline=false, $color='', $style=-1);

换行

Ln($h='', $cell=false);
Ln(行数, 是否cell);
例如:
$pdf->SetProtection(array('print','modify','copy','annot-forms'), '854230');

图片背景

Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border);

注意:把图片放语句放在前面,并且使用绝对坐标定位,即可做背景。

原文地址:https://www.cnblogs.com/520fyl/p/5396374.html