http://www.fpdf.org/en/script/script3.phpHere's an example of multi-page table with random content:<?php define('FPDF_FONTPATH','font/'); require('mc_table.php');function GenerateWord() { //Get a random word $nb=rand(3,10); $w=''; for($i=1;$i<=$nb;$i++) $w.=chr(rand(ord('a'),ord('z'))); return $w; }function GenerateSentence() { //Get a random sentence $nb=rand(1,10); $s=''; for($i=1;$i<=$nb;$i++) $s.=GenerateWord().' '; return substr($s,0,-1); }$pdf=new PDF_MC_Table(); $pdf->Open(); $pdf->AddPage(); $pdf->SetFont('Arial','',14); //Table with 20 rows and 4 columns $pdf->SetWidths(array(30,50,30,40)); srand(microtime()*1000000); for($i=0;$i<20;$i++) $pdf->Row(array(GenerateSentence(),GenerateSentence(),GenerateSentence(),GenerateSentence())); $pdf->Output(); ?> Result: http://www.fpdf.org/en/script/ex3.pdf
require('fpdf.php');$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
不过,有个问题:怎么让导出的内容在pdf中还是表格的方式保存,而且,表格栏的宽度固定,而高度随内容大小自由调节。这个,在fpdf中没有实现,它的cell可以做成表格,但高度不能自由调节;multicell高度可以自由调节,但无法做成表格。最近在研究从mysql文件导出或导入其它格式文件(其实,这个问题我断断续续研究4年多了)
实现的有:txt文件,xml文件,doc文件,excel文件,access数据库,mssql文件,oracle文件。 但pdf文件至今还不够完善,很伤脑筋。我现在觉得,php有几大领域值得研究:一是数据交换,二是报表图像处理,三是各类优化。
define('FPDF_FONTPATH','font/');
require('mc_table.php');function GenerateWord()
{
//Get a random word
$nb=rand(3,10);
$w='';
for($i=1;$i<=$nb;$i++)
$w.=chr(rand(ord('a'),ord('z')));
return $w;
}function GenerateSentence()
{
//Get a random sentence
$nb=rand(1,10);
$s='';
for($i=1;$i<=$nb;$i++)
$s.=GenerateWord().' ';
return substr($s,0,-1);
}$pdf=new PDF_MC_Table();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial','',14);
//Table with 20 rows and 4 columns
$pdf->SetWidths(array(30,50,30,40));
srand(microtime()*1000000);
for($i=0;$i<20;$i++)
$pdf->Row(array(GenerateSentence(),GenerateSentence(),GenerateSentence(),GenerateSentence()));
$pdf->Output();
?>
Result: http://www.fpdf.org/en/script/ex3.pdf