JpGraph联合TCPDF动态生成图文并茂的PDF文件(3)

2. 安装tcpdf
解压tcpdf压缩包到/usr/share/php5目录

因为安装jpgraph时已经将/usr/share/php5目录添加到php的搜索路径中,所以这里就不必修改php.ini了

3. 测试tcpdf
建立文件tcpdf,内容如下:

#!/usr/bin/php -q
<?
require_once('tcpdf/config/lang/eng.php');

require_once('tcpdf/tcpdf.php');

// create new PDF document

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

$pdf->SetSubject('TCPDF Tutorial');

$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// remove default header/footer

$pdf->setPrintHeader(false);

$pdf->setPrintFooter(false);


// 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 default monospaced font

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


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


// ---------------------------------------------------------


// add a page

$pdf->AddPage();


// set JPEG quality

$pdf->setJPEGQuality(75);


// Image example
$pdf->Image('/tmp/test1.png', 50, 50, 100, 100, '', 'http://www.tcpdf.org', '', true, 150);
$pdf->Cell( 0, 0, 'TCPDF test', 0, 1 );;

// ---------------------------------------------------------


//Close and output PDF document

$pdf->Output('example.pdf', 'D');
?>

给上述文件添加执行权限然后执行,生成pdf如下:

JpGraph联合TCPDF动态生成图文并茂的PDF文件

这里只是简单测试,把jpgraph动态生成的图形包含到pdf,若要把pdf整的更加美观,需详细查看jpgraph和tcpdf库。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/19204.html