sglms/pdf
Composer 安装命令:
composer require sglms/pdf
包简介
Simple Laravel wrapper for mPDF with fluent view rendering and signing helpers.
关键字:
README 文档
README
Simple Laravel wrapper around mPDF with a fluent API for rendering Blade views, attaching headers/footers, and signing documents.
Requirements
- PHP >= 8.3
- Laravel 12
- mPDF 8.2+
Installation
composer require sglms/pdf
Laravel package discovery registers the service provider and facade automatically.
Quick Start
use Sglms\Pdf\Facades\Pdf; Pdf::view('pdf.invoice', ['order' => $order])->output('invoice.pdf');
Usage
Initialize with configuration
use Sglms\Pdf\Facades\Pdf; $pdf = Pdf::init( config: ['format' => 'Letter'], stylesheet: 'css/pdf.css', header: 'pdf.header', footer: 'pdf.footer' );
Render one or multiple views
$pdf->view('pdf.page-one', ['name' => 'Jane']) ->view('pdf.page-two') ->output('document.pdf');
Add logo for header/footer views
The logo is available in mPDF templates as var:logo.
$pdf->logo('images/logo.svg');
If your header or footer uses the logo, call logo() before header() / footer().
Add signature block
$pdf->sign( signature: 'pdf.signature', data: ['name' => 'John Doe'], x: 50, y: 100, width: 100 );
Sign existing PDF
$pdf->signFile('pdf.signature', storage_path('app/base.pdf'));
Output options
// Raw string — pass to Laravel's response() helper $raw = $pdf->output('document.pdf'); $raw = $pdf->string(); // alias, no filename context // Write to an absolute file path $pdf->save(storage_path('app/a.pdf')); // Laravel Storage disk $pdf->storeAs('a.pdf', 'public'); // Stream directly to the browser (bypasses Laravel response) $pdf->inline('document.pdf'); // Content-Disposition: inline $pdf->download('document.pdf'); // Content-Disposition: attachment
Access underlying mPDF instance
$mpdf = $pdf->get();
Controller Example
use App\Http\Controllers\Controller; use Sglms\Pdf\Facades\Pdf; class CustomController extends Controller { public function render() { $bytes = Pdf::view('pdf.filename') ->sign('pdf.signature') ->output('document.pdf'); return response($bytes, 200) ->header('Content-Type', 'application/pdf') ->header('Content-Disposition', 'inline; filename="document.pdf"'); } }
Notes
- mPDF applies headers/footers from the point they are set. Set header/footer before the first rendered body view when possible.
- This package is intentionally lightweight and optimized for straightforward document-generation workflows.
License
MIT
sglms/pdf 适用场景与选型建议
sglms/pdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 210 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「mpdf」 「signature」 「laravel」 「sglms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sglms/pdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sglms/pdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sglms/pdf 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
接口签名验证
Laravel MPdf : Easily generate PDF files with arabic support
Digital signature Nova field.
Generate PDFs in Laravel with this mPDF wrapper.
Generate PDFs in Laravel with this mPDF wrapper.
Zoho Sign v1 API PHP Wrapper - PHP 7.4 Ready
统计信息
- 总下载量: 210
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-08