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));
- 設置頁眉和頁腳字體
$pdf->setHeaderFont(Array('stsongstdlight', '', '10')); $pdf->setFooterFont(Array('helvetica', '', '8'));
- 設置默認等寬字體
$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);
注意:把圖片放語句放在前面,並且使用絕對坐標定位,即可做背景。