What is FPDF?
FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. The advantage is that PDFlib requires a fee for a commercial usage. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
FPDF可以让我们创建pdf文件而不用去调用PDFlib
这里可以下到最新的windows下的版本:
[url]http://www.fpdf.org/en/dl.php?v=152&f=zip[/url]
这里可以下到中文手册:
[url]http://www.fpdf.org/en/dl.php?id=72[/url]
若要其他版本可以到这里下到:
[url]http://www.fpdf.org/[/url]
本例中所用的 chinese.php下载
TEST1
<?php
require('chinese.php');
class PDF extends PDF_Chinese
{
//Page header
function Header()
{
$pdf->SetFont('GB','',10);
$pdf->Write(10,'头Test中文测试');
}
//Page footer
function Footer()
{
$pdf->SetFont('GB','',10);
$pdf->Write(10,'尾 Test中文测试');
}
}
//Instanciation of inherited class
$pdf=new PDF_Chinese();
$pdf->AddGBFont();
$pdf->Open();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('GB','',12);
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,'中文测试 '.$i,0,1); //this can output correct
$pdf->Output();
?>
TEST2
<?php
require('chinese.php');
$body="--测试--";//some text in chinese
//Instanciation of inherited class
$pdf=new PDF_Chinese();
$pdf->AddGBFont();
$pdf->Open();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('GB','',20);
$pdf->SetTextColor(255,0,0);
$pdf->text(60,10,'成都市武侯区人民政府文件 ');// display chinese correctly
$pdf->SetDrawColor(255,0,0);
$pdf->line(30,15,180,15);
$pdf->SetTextColor(0,0,0);
$pdf->text(60,30,'$body');//display '$body' not the variable value
$pdf->Output();
?>
TEST3
<?php
require('chinese.php');
$pdf=new PDF_Chinese();
$pdf->AddGBFont('simsun','宋体');
$pdf->AddGBFont('simhei','黑体');
$pdf->AddGBFont('simkai','楷体_GB2312');
$pdf->AddGBFont('sinfang','仿宋_GB2312');
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('simsun','',20);
$pdf->Write(10,'哈尔滨');
$pdf->SetFont('simhei','',20);
$pdf->Write(10,'哈尔滨');
$pdf->SetFont('simkai','',20);
$pdf->Write(10,'哈尔滨');
$pdf->SetFont('sinfang','',20);
$pdf->Write(10,'哈尔滨');
$pdf->Output();
?>
添加一个外框,做表格且输出文件的方法
<?
require('fpdf152/chinese.php');
$pdf=new PDF_Chinese();
$pdf->AddGBFont('sinfang','仿宋_GB2312');
$pdf->Open();
$pdf->AddPage();
$pdf->Rect(5,5,200,280);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('sinfang','',10);
$pdf->Cell(20,10,'海底',1,0);
$pdf->Cell(20,10,'世界',1,0);
$pdf->SetDisplayMode("real");
//直接通过IE浏览器输出
//$pdf->Output();
//生成文件供下载
$pdf->Output("a.pdf","D");
?>
今天又认真地研究了一下FPDF的功能,实现了相对复杂的表格绘制工作。
只是可惜还是无法实现竖排文字单元格再接一个单元格,哎,难道E文就没有竖排的概念吗?!郁闷...
演示地址:[url]http://service.friendshow.com/jxxysong/PDF/test03.php[/url]
原文件提供:[url]http://www.c51net.com/pdf.rar[/url]
PDF+PHP的完美结合 【转】
最新推荐文章于 2024-08-19 09:53:26 发布