safermobility/laravel-gotenberg
最新稳定版本:v1.0.2
Composer 安装命令:
composer require safermobility/laravel-gotenberg
包简介
Create PDFs in Laravel apps using Gotenberg
README 文档
README
This package provides a simple way to create PDFs in Laravel apps. Under the hood it uses Gotenberg to generate PDFs from Blade views. You can use modern CSS features like grid and flexbox to create beautiful PDFs.
This package is very heavily based on Spatie's laravel-pdf package, but does not require Node.js to run, making it more suitable for applications that run in containers.
Installation
You can install the package via composer:
composer require safermobility/laravel-gotenberg
You can publish the config file with:
php artisan vendor:publish --tag="gotenberg-config"
This is the contents of the published config file:
return [ 'host' => env('GOTENBERG_HOST'), ];
Usage
You must have a working Gotenberg instance.
For development, you may be able to use the Gotenberg Demo server:
GOTENBERG_HOST=https://demo.gotenberg.dev
For production, you must set up your own Gotenberg instance.
Simple PDF generation
use SaferMobility\LaravelGotenberg\Facades\Gotenberg; Gotenberg::view('pdfs.invoice', ['invoice' => $invoice]) ->format('letter') ->save('invoice.pdf')
This will render the Blade view pdfs.invoice with the given data and save it as a PDF file.
You can also return the PDF as a response from your controller:
use SaferMobility\LaravelGotenberg\Facades\Gotenberg; class DownloadInvoiceController { public function __invoke(Invoice $invoice) { return Gotenberg::view('pdfs.invoice', ['invoice' => $invoice]) ->format('letter') ->name('your-invoice.pdf'); } }
This will use a streamed response to reduce memory usage.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
- SaferMobility
- Spatie - for their Laravel PDF package, and many others
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 2.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-01