breuer/laravel-pdf-chrome-driver
Composer 安装命令:
composer require breuer/laravel-pdf-chrome-driver
包简介
Chrome DevTools Protocol driver for spatie/laravel-pdf
README 文档
README
A Chrome DevTools Protocol (CDP) driver for spatie/laravel-pdf. Renders PDFs by communicating directly with chrome-headless-shell over CDP pipes — no Node.js, no Puppeteer, no Docker, no external services.
Requirements
- PHP 8.2+
- Laravel 11+
- spatie/laravel-pdf ^2.0
Installation
Install the package via Composer:
composer require breuer/laravel-pdf-chrome-driver
Download the headless Chrome binary:
php artisan pdf-chrome-driver:install
Set the driver in your config/laravel-pdf.php:
'driver' => 'chrome',
Or via your .env file:
LARAVEL_PDF_DRIVER=chrome
That's it. All spatie/laravel-pdf functionality now uses Chrome CDP under the hood.
Usage
This package is a driver for spatie/laravel-pdf — use spatie's API as documented in their README:
use Spatie\LaravelPdf\Facades\Pdf; Route::get('/pdf', function () { return Pdf::view('invoice', ['order' => $order]); });
Configuration
Configure the Chrome binary path and timeout in config/laravel-pdf.php:
'chrome' => [ 'path' => env('LARAVEL_PDF_CHROME_PATH'), 'timeout' => env('LARAVEL_PDF_CHROME_TIMEOUT', 10), ],
Custom install directory
You can install to a custom directory with --path. Relative paths resolve from the project root:
# Install a specific Chrome milestone php artisan pdf-chrome-driver:install 137 # Install to a custom directory php artisan pdf-chrome-driver:install --path=storage/browser # Absolute paths work too php artisan pdf-chrome-driver:install --path=/opt/chrome
When using --path, configure the binary path so the driver can find it:
'chrome' => [ 'path' => storage_path('browser/chrome-headless-shell-linux64/chrome-headless-shell'), ],
This is useful for deployment tools like Envoyer where the vendor directory changes on each deploy but storage persists across releases.
Linux ARM64
Pre-built Chrome binaries are not available for Linux ARM64. Install Chromium via your package manager and point to it:
LARAVEL_PDF_CHROME_PATH=/usr/bin/chromium
How it works
Unlike other drivers that shell out to Node.js or rely on external services, this driver:
- Launches
chrome-headless-shellwith--remote-debugging-pipe - Communicates over CDP via file descriptors (fd 3/4) — no WebSocket, no port allocation
- Injects HTML via
Page.setDocumentContent— no temp files - Generates PDF via
Page.printToPDF
Each request gets an isolated Chrome process with its own temp directory, cleaned up automatically.
License
This package is open-sourced software licensed under the MIT License. Please see the License File for more information.
统计信息
- 总下载量: 680
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-04