PHP 生成 PDF 的又一个选择——TCPDF

http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf

今天在 sourceforge 上看到了 2.7.001 放出了。看了一下例子,貌似很好用的样子。

安装也很简单,关键就是配置 config/tcpdf_config.php 文件中的 K_PATH_MAIN 和 K_PATH_URL,分别设置为物理路径和 URL 地址。

require_once('config/lang/eng.php');
require_once(
'tcpdf.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);

// 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
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// 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 margins
$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
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

//initialize document
$pdf->AliasNbPages();

// add a page
$pdf->AddPage();

// ———————————————————

// set font
$pdf->SetFont(“vera”, “BI”, 20);

// print a line using Cell()
$pdf->Cell(0,10,“Example 001”,1,1,‘C’);

// ———————————————————

//Close and output PDF document
$pdf->Output();

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *