sglms/pdf
最新稳定版本:0.3
Composer 安装命令:
composer require sglms/pdf
包简介
A simple (but efficient) mPDF wrapper for Laravel (>=12).
README 文档
README
Simple Laravel (^12.0) wrapper for Mpdf, using Laravel's view components.
Installation
composer require sglms/pdf
Laravel's auto-discovery features will register the service provider and facade.
Usage
For the impatient:
use Sglms\Pdf; $pdf = Pdf::view('pdf.filename')->output('filename.pdf');
View Parameters
use Sglms\Pdf; $pdf = Pdf::view( 'pdf.filename', ['param' => 'value'] /* [Optional */ ); $pdf->output('filename.pdf'); /* Or, ... */ $pdf->save('filename'); /* Or, store it 'the Laravel way' */ $pdf->storeAs('filename', 'disk');
Configuration and Header/Footer
$pdf = Pdf::init( config: ['format' => 'letter'], header: 'pdf.header', footer: 'pdf.footer' stylesheet: 'path/to/stylesheet.css' );
Add your logo (available as 'var:logo' in your views):
$pdf->logo('path/to/logo.svg');
Remember to add your logo before header/footer setup, if you plan to use it there.
You can override the setup if you need parameters:
$pdf->header('pdf.header', ['param' => 'value']); $pdf->footer('pdf.footer', ['param' => 'value']);
Include your header before adding views to the pdf. This is a limitation of mPDF in that it calls AddPage() when you include a view (or any other html), and if the header is not set, mpdf will render the header blank.
Concatenate multiple views:
$pdf = Pdf::init(); $pdf->view('pdf.one')->view('pdf.two')->output('filename.pdf');
Sign your document:
$pdf->sign('pdf.signature', ['name' => 'John Doe']);
Or, ...
$pdf->sign( signature: 'pdf.signature', data: ['name' => 'John Doe'], x: 50, /* [mm] */ y: 100, /* [mm] */ width: 100 /* [mm] */ );
You can also load and sign an existing PDF file:
$pdf->signFile('pdf.signature, 'path/to/pdf');
If you need the base mPDF to work on it further:
$pdf->get();
Use it in your controller
use Sglms\Pdf; class CustomController extendes Controller { // ... public function render() { $pdf = Pdf::view('pdf.filename')->sign('pdf.signature'); return response($pdf->output(), 200) ->header('Content-Type', 'application/pdf') ->header('Content-Disposition', 'inline; filename="document.pdf"'); } //... }
Limitations
As mentioned, very simple (but efficient) wrapper, that works with Laravel 12 (php >=8.3; mpdf >= 8.x).
It's better suited for single page document generation.
Rationale
This package is part of a larger project in which we needed to generate a large number of one-page documents and (digitally) sign them.
License
Sglms/Pdf is licensed under the The MIT License.
统计信息
- 总下载量: 72
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-08