TCPDF說明文檔php
require_once('tcpdf.php');html
2、實例化TCPDF類 頁面方向(P =肖像,L =景觀)、測量(mm)、頁面格式$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); web
3、設置文檔信息設置文檔信息----文件創做者數組
$pdf->SetCreator('Helloweba'); $pdf->SetAuthor('yueguangguang'); $pdf->SetTitle('Welcome to helloweba.com!'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, PHP');
4、設置默認標題數據瀏覽器
$pdf->SetHeaderData(PDF_HEADER_LOGO,PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 038', PDF_HEADER_STRING);
5、設置頁眉和頁腳信息安全
//Page header public function Header() { // Logo $image_file = K_PATH_IMAGES.'bl_logo.png'; $this->Image($image_file, 10, 5, 8, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false); // Set font $this->SetFont('stsongstdlight', 'B', 10); // Title $this->Write(8, '山東保藍環保'); $this->Cell(0, 0, '技術方案', 0, false, 'R', 0, '', 0, false, 'M', 'M'); } // Page footer public function Footer() { // Position at 15 mm from bottom $this->SetY(-15); // Set font $this->SetFont('stsongstdlight', 'I', 8); // Page number $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); }
6、設置字體服務器
$pdf->SetFont('stsongstdlight', '', 12);
7、添加一個頁面tcp
$pdf->AddPage();
8、該方法從當前位置打印文本字體
(行高,文本變量,經過AddLink()返回的URL或標識符,背景畫,容許中心或對齊文本,若是正確設置光標底部的線,不然設置遊標的行,字體延伸模式,若是真的只打印第一行並返回剩餘的字符串,若是真正的字符串是一行的開始,最大高度,補白)ui
$pdf->Write(0,$str1,'', 0, 'L', true, 0, false, false, 0);
9、安全密碼設置
$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 );
10、輸出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