peal/
使用 Laravel 的 PDF 文档包
dev-master
2018-08-06 12:15 UTC
Requires
- illuminate/support: 5.6.*
This package is auto-updated.
Last update: 2024-09-14 18:42:20 UTC
README
FPDF 是一个 PHP 类,允许使用纯 PHP 生成 PDF 文件,也就是说不使用 PDFlib 库。FPDF 中的 F 代表 Free:您可以使用它进行任何类型的用途,并修改它以满足您的需求。FPDF 还具有其他优势:高级函数。
安装
在您的项目根目录中,打开您的终端
composer require peal/larapdf
Composer 将自动下载所有依赖项。
对于 Laravel
完成安装后,打开配置文件夹中的 app.php,在 providers 数组中粘贴以下行
peal\larapdf\PdfServiceProvider::class,
为了 Facade 支持,在 aliases 数组中粘贴以下行
'Pdf' => peal\larapdf\Facades\Pdf::class,
然后运行此命令
php artisan vendor:publish --provider="peal\larapdf\PdfServiceProvider"
在 vendor 发布后检查您的配置文件夹中是否已创建 pdf-config.php。
/* * FPDF class * */ return [ 'pdfservice' => peal\larapdf\FPDF::class, ];
基本设置
$pdf = App::make('pdf'); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output();
您可以将它们串联起来
$pdf = App::make('pdf'); $pdf->AddPage() ->SetFont('Arial','B',16) ->Cell(40,10,'Hello World!') ->Output();
或者
use peal\larapdf\Facades\Pdf; Pdf::AddPage() ->SetFont('Arial','B',16) ->Cell(40,10,'Hello World!') ->Output();
不使用 Facade 的高级用法
在您的控制器方法中
$row_height = 6; $y_axis = 50; $y_axis = $y_axis + $row_height; $pdf = App::make('pdf'); $pdf->AddPage() ->SetFont('Arial','B',16) ->Cell(0,10,"SAIC Institute of Management & Technology",0,0,'C') ->SetFont('Arial','B',12) ->Cell(-65, 30, 'Begum Rokeya Avenue, Dhaka',0,'C',0) ->Cell(-11, 50, 'Phone: 01936-005816',0,'C',0) ->SetFillColor(232, 232, 232) ->SetY(50) ->SetX(25) ->SetFont('Arial', 'B', 10) ->Cell(20, 6, 'Room No', 1, 0, 'L', 1) ->Cell(20, 6, 'Seat No', 1, 0, 'L', 1) ->Cell(30, 6, 'Student ID', 1, 0, 'L', 1) ->Cell(60, 6, 'Student Name', 1, 0, 'L', 1) ->Cell(20, 6, 'Seat Rent', 1, 0, 'L', 1) ->Cell(25, 6, 'Meal Charge', 1, 0, 'L', 1) ->SetY($y_axis) ->SetX(25) ->SetFont('Arial', '', 10) ->Cell(20, 6, 200, 1, 0, 'L', 1) ->Cell(20, 6, 201, 1, 0, 'L', 1) ->Cell(30, 6, 'CMT2018002', 1, 0, 'L', 1) ->Cell(60, 6, "Saiful Islam", 1, 0, 'L', 1) ->Cell(20, 6, 2000, 1, 0, 'L', 1) ->Cell(25, 6, 50, 1, 0, 'L', 1) ->Output();
使用 Facade 的高级用法
在您的控制器方法中
use peal\larapdf\Facades\Pdf; $row_height = 6; $y_axis = 50; $y_axis = $y_axis + $row_height; Pdf::AddPage() ->SetFont('Arial','B',16) ->Cell(0,10,"SAIC Institute of Management & Technology",0,0,'C') ->SetFont('Arial','B',12) ->Cell(-65, 30, 'Begum Rokeya Avenue, Dhaka',0,'C',0) ->Cell(-11, 50, 'Phone: 01936-005816',0,'C',0) ->SetFillColor(232, 232, 232) ->SetY(50) ->SetX(25) ->SetFont('Arial', 'B', 10) ->Cell(20, 6, 'Room No', 1, 0, 'L', 1) ->Cell(20, 6, 'Seat No', 1, 0, 'L', 1) ->Cell(30, 6, 'Student ID', 1, 0, 'L', 1) ->Cell(60, 6, 'Student Name', 1, 0, 'L', 1) ->Cell(20, 6, 'Seat Rent', 1, 0, 'L', 1) ->Cell(25, 6, 'Meal Charge', 1, 0, 'L', 1) ->SetY($y_axis) ->SetX(25) ->SetFont('Arial', '', 10) ->Cell(20, 6, 200, 1, 0, 'L', 1) ->Cell(20, 6, 201, 1, 0, 'L', 1) ->Cell(30, 6, 'CMT2018002', 1, 0, 'L', 1) ->Cell(60, 6, "Saiful Islam", 1, 0, 'L', 1) ->Cell(20, 6, 2000, 1, 0, 'L', 1) ->Cell(25, 6, 50, 1, 0, 'L', 1) ->Output();
对于核心 PHP
use peal\larapdf\Mediator\Pdf; use peal\larapdf\FPDF; $pdf = new Pdf(new FPDF()); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output();