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);

五、設置頁眉和頁腳信息

//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');
        }

六、設置字體

$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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM