php fpdf类库

作者admin

8月 9, 2024

FPDF 是一个用于生成 PDF 文件的 PHP 库,轻量级且易于使用。FPDF 可以用来创建各种类型的 PDF 文档,如报告、发票、合同等。

github: https://github.com/Setasign/FPDF

安装FPDF

composer require fpdf/fpdf

使用FPDF

require(‘path/to/fpdf.php’);

#创建 PDF 对象
$pdf = new FPDF();

#添加页面
$pdf->AddPage();

#设置字体
$pdf->SetFont(‘Arial’, ‘B’, 16);

#添加单行文本
$pdf->Cell(40, 10, ‘Hello World!’);

#添加多行文本
$pdf->MultiCell(0, 10, ‘This is a multiline text example.’); // 0 表示自动换行

#添加图像
$pdf->Image(‘path/to/image.jpg’, 10, 10, 50, 50);

#添加链接
$pdf->SetTextColor(0, 0, 255);
$pdf->SetFont(”, ‘U’);
$pdf->Cell(0, 10, ‘Visit FPDF website’, 0, 1, ‘L’, false, ‘http://www.fpdf.org’);

#保存到文件
$pdf->Output(‘F’, ‘path/to/file.pdf’);

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

作者 admin

百度广告效果展示