首先下载一份FPDF文件

<?php

//define('FPDF_FONTPATH','font/timesi'); //定义font文件夹所在路径

require_once('FPDF/fpdf.php'); //包含fpdf类库文件

$pdf=new FPDF(); //创建新的FPDF对象,竖向放纸,单位为毫米,纸张大小A4

$pdf->Open(); //开始创建PDF

$pdf->AddPage(); //增加一页

$pdf->SetFont('Arial','',14); //设置字体样式

$header=array('Name','Age','Sex','Salary'); //设置表头

$data=array(); //设置表体

$data[0] = array('Simon','24','Male','5,000.00');

$data[1] = array('Elaine','25','Female','6,000.00');

$data[2] = array('Susan','25','Female','7,000.00');

$data[3] = array('David','26','Male','8,000.00');

$width=array(40,40,40,40); //设置每列宽度

for($i=0;$i<count($header);$i++) //循环输出表头

    $pdf->Cell($width[$i],6,$header[$i],1);

$pdf->Ln();

foreach($data as $row) //循环输出表体

{

    $pdf->Cell($width[0],6,$row[0],1);

    $pdf->Cell($width[1],6,$row[1],1);

    $pdf->Cell($width[2],6,$row[2],1);

    $pdf->Cell($width[3],6,$row[3],1);

    $pdf->Ln();

}

$pdf->Output(); //输出PDF到浏览器

?>

posted on 2013-07-19 14:19  幸福之家128817  阅读(181)  评论(0)    收藏  举报