我曾多次使用fpdf创建基于php的pdf文档,以下是一个示例:
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddFont('georgia', '', 'georgia.php');
$pdf->AddFont('georgia', 'B', 'georgiab.php');
$pdf->AddFont('georgia', 'I', 'georgiai.php');
$pdf->AddFont('freesans', '', 'freesans.php', true);
$pdf->SetFont('freesans', '', 12);
$pdf->SetTitle('My title');
$pdf->SetAuthor('My author');
$pdf->SetDisplayMode('fullpage', 'single');
$pdf->SetLeftMargin(20);
$pdf->SetRightMargin(20);
$pdf->AddPage();
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
你可以通过网站本身的教程快速学习。
编辑:保存表单数据的示例(是的,非常容易...)
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
foreach ($_POST as $key =>$data)
{
$pdf->Write(5, "$key: $data");
$pdf->Ln(10);
}
$pdf->Output($path_to_file . 'file.txt','F');
看看这些使用fpdf创建的页面,真的很棒!
![在此输入图片描述](https://istack.dev59.com/dWmeq.webp)
![在此输入图片描述](https://istack.dev59.com/RJwKB.webp)