1. 程式人生 > >TCPDF的example_001.php的引數解釋

TCPDF的example_001.php的引數解釋

<?php
//============================================================+
// File name   : example_001.php
// Begin       : 2008-03-04
// Last Update : 2013-05-14
//
// Description : Example 001 for TCPDF class
//               Default Header and Footer
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com LTD
// www.tecnick.com // [email protected] //============================================================+ /** * Creates an example PDF TEST document using TCPDF * @package com.tecnick.tcpdf * @abstract TCPDF - Example: Default Header and Footer * @author Nicola Asuni * @since 2008-03-04 */
// Include the main TCPDF library (search for installation path). require_once('tcpdf_include.php'); // create new PDF document /** * 引數解釋 * 1 樣式排版 P/L 豎向/橫向 * 2 測量單位 pt(point)/mm(millimeter)/cm(centimeter)/in(inch) 磅/毫米/釐米/英寸 * 3 輸入的文字內容是否經過編碼 true/false 預設true * 4 文字的編碼格式,因為輸入html的時候,是可以指定頁面的編碼方式的,所以特別針對那個設定了這個引數 預設 UTF-8 * 5 是否開啟磁碟儲存 true/false 建議不開啟 預設 false * 6 pdfa是pdf格式的一種,主要為了長期儲存,所以關閉了一些功能,這裡就是詢問是否開啟PDF/A 模式,預設false * getPageSizeFromFormat(), setPageFormat(),說去看這兩個函式,再說吧 */
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR);// 建立者 $pdf->SetAuthor('Nicola Asuni');// 作者 $pdf->SetTitle('TCPDF Example 001');// 標題 $pdf->SetSubject('TCPDF Tutorial');// 主題 $pdf->SetKeywords('TCPDF, PDF, example, test, guide');// 關鍵字 // set default header data /** * 引數解釋 * 1 頁面頂部logo的url地址 * 2 頁面頂部logo的寬度 * 3 頁面頂部的標題 * 4 頁面頂部的文字 * 5 RGB,文字顏色 * 6 RGB,行顏色 */ $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128)); /** * 引數解釋 * 1 底部文字顏色 * 2 底部行的顏色 */ $pdf->setFooterData(array(0,64,0), 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 /** * 引數解釋,左,上,右的縮排距離, * 最後一個引數是是否所有頁面都按照這個值,如果是true的話,則接下來頁面的單獨設定將失效 */ $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 /** * 引數解釋 * 是否開啟自動截斷模式,如果頁面底部的元素超過設定值,則自動跳轉到下一頁,這個值預設是2cm * 1 是否開啟這個設定 * 2 距離 */ $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor /** * 設定圖片縮放比例 */ $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l); } // --------------------------------------------------------- // set default font subsetting mode /** * 是否開啟字型子集 */ $pdf->setFontSubsetting(true); // Set font // dejavusans is a UTF-8 Unicode font, if you only need to // print standard ASCII chars, you can use core fonts like // helvetica or times to reduce file size. /** * 設定字型 * 引數解釋 * 1 字型名字 * 2 字型樣式,支援一些快捷設定,但是還是直接寫CSS吧,還有一些效果對一些特殊字型沒有效果 * 3 字型大小,單位是points,預設是12英鎊 * 4 字型庫檔案 * 5 子集庫是否開啟 */ $pdf->SetFont('dejavusans', '', 14, '', true); // Add a page // This method has several options, check the source code documentation for more information. /** * 新建一個頁面 * 引數解釋 * 1 方向 P/L * 2 頁面大小,可以是 getPageSizeFromFormat()/setPageFormat() * 3 是否依舊採用$pdf設定的左,上,右的偏移量 * 這裡再說一下getPageSizeFromFormat()函式就是返回一個兩個值的陣列 */ $pdf->AddPage(); // set text shadow effect /** * 設定文字的陰影效果,我用不到,所以自己去搜原始碼吧 */ $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal')); // Set some content to print $html = <<<EOD <h1>Welcome to <a href="http://www.tcpdf.org" style="text-decoration:none;background-color:#CC0000;color:black;">&nbsp;<span style="color:black;">TC</span><span style="color:white;">PDF</span>&nbsp;</a>!</h1> <i>This is the first example of TCPDF library.</i> <p>This text is printed using the <i>writeHTMLCell()</i> method but you can also use: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>.</p> <p>Please check the source code documentation and other examples for further information.</p> <p style="color:#CC0000;">TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE <a href="http://sourceforge.net/donate/index.php?group_id=128076">MAKE A DONATION!</a></p> EOD; // Print text using writeHTMLCell() /** * 引數解釋 * 1 寬度,0的話,就配合左右的偏移量,充滿整個螢幕 * 2 最小高度,如果內容超過則會自動增加 * 3 距離左上角,在X軸上的距離 * 4 距離左上角,在Y軸上的距離 * 5 $html,傳入的輸入值 * 6 邊框,可選值為 0 無邊框 1 有邊框,或者一個包含以下內容的字串,或者一個數組,他只給了陣列的例子,所以直接看陣列吧: * array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))) * 7 該部分內容填充完成後,接下來將從哪裡開始輸出內容,可選值有 0 右側 1 另起一行 2 下一頁 * 8 該部分內容的背景是否要採用$html設定的值,還是採用系統定義好的值 * 9 是否重新計算底部的高度? * 10 文字的對齊方式 L 左對齊 C 居中 R 右對齊 * 11 系統將計算padding值,保證每行的寬度都是一致的 */ $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); // --------------------------------------------------------- $filePath="/Users/yangqingxian/Desktop/PDFExample/"; // Close and output PDF document // This method has several options, check the source code documentation for more information. /** * 引數解釋 * 1 儲存的檔名 * 2 檔案的輸出方式 I 預覽模式 D 下載模式 F 儲存到本地資料夾 S 將檔案內容作為字串返回,FI=F+I,FD=F+D,E,將返回email的附件形式 */ $pdf->Output('example_001.pdf', 'F'); //============================================================+ // END OF FILE //============================================================+