定制 ycchuang99/laravel-pdf-chrome-driver 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ycchuang99/laravel-pdf-chrome-driver

最新稳定版本:1.2.0

Composer 安装命令:

composer require ycchuang99/laravel-pdf-chrome-driver

包简介

A chrome-php/chrome driver for spatie/laravel-pdf

README 文档

README

Warning

This package is abandoned and no longer maintained. Please use spatie/laravel-pdf instead.

A chrome-php/chrome driver for spatie/laravel-pdf.

This package provides a PDF generation driver that uses chrome-php/chrome (a PHP library for headless Chrome) instead of Browsershot. No Node.js required — pure PHP communication with Chrome via the DevTools Protocol.

Requirements

  • PHP 8.2+
  • Chrome or Chromium binary installed on the system
  • spatie/laravel-pdf ^2.0

Version Compatibility

Package Version PHP spatie/laravel-pdf chrome-php/chrome
1.x ^8.2 ^2.0 ^1.0

Installation

composer require ycchuang99/laravel-pdf-chrome-php-driver

The service provider is auto-discovered by Laravel.

Configuration

Set the driver in your .env file:

LARAVEL_PDF_DRIVER=chrome-php

Available Configuration Options

Add to your config/laravel-pdf.php:

'chrome-php' => [
    'chrome_path'               => env('LARAVEL_PDF_CHROME_PATH'),
    'no_sandbox'                => env('LARAVEL_PDF_NO_SANDBOX', false),
    'timeout'                   => env('LARAVEL_PDF_TIMEOUT', 30000),
    'startup_timeout'           => env('LARAVEL_PDF_STARTUP_TIMEOUT', 30),
    'window_size'               => null,
    'custom_flags'              => null,
    'user_data_dir'             => null,
    'env_variables'             => null,
    'ignore_certificate_errors' => env('LARAVEL_PDF_IGNORE_CERT_ERRORS', false),
    'send_sync_default_timeout' => env('LARAVEL_PDF_SEND_SYNC_DEFAULT_TIMEOUT'),
    'excluded_switches'         => null,
],

Environment Variables

Variable Description Default
LARAVEL_PDF_DRIVER Set to chrome-php to use this driver browsershot
LARAVEL_PDF_CHROME_PATH Path to Chrome/Chromium binary Auto-detected
LARAVEL_PDF_NO_SANDBOX Disable sandbox (required in Docker) false
LARAVEL_PDF_TIMEOUT Timeout in milliseconds 30000
LARAVEL_PDF_STARTUP_TIMEOUT Chrome startup timeout in seconds 30
LARAVEL_PDF_IGNORE_CERT_ERRORS Ignore SSL certificate errors false
LARAVEL_PDF_SEND_SYNC_DEFAULT_TIMEOUT Default timeout (ms) for synchronous CDP messages null (library default: 5000)

Usage

Works exactly like spatie/laravel-pdf — just change the driver:

use Spatie\LaravelPdf\Facades\Pdf;

// Generate and save a PDF
Pdf::view('invoice', ['order' => $order])
    ->format('a4')
    ->save('/path/to/invoice.pdf');

// With all options
Pdf::html('<h1>Hello World</h1>')
    ->format('a4')
    ->landscape()
    ->margins(10, 10, 10, 10, 'mm')
    ->headerHtml('<div style="font-size:10px">Header</div>')
    ->footerHtml('<div style="font-size:10px">Page <span class="pageNumber"></span></div>')
    ->scale(0.9)
    ->save('/path/to/output.pdf');

// Use driver per-call (without changing default)
Pdf::view('invoice', $data)
    ->driver('chrome-php')
    ->save('/path/to/invoice.pdf');

Docker / CI Usage

When running in Docker or CI environments, enable no-sandbox mode and add the recommended Chrome flags:

// config/laravel-pdf.php
'chrome-php' => [
    'no_sandbox'     => true,
    'env_variables'  => ['HOME' => '/tmp', 'XDG_CONFIG_HOME' => '/tmp/.config'],
],

Or via environment variables (for no_sandbox only):

LARAVEL_PDF_NO_SANDBOX=true
Variable Value Purpose
no_sandbox true Disables Chrome's sandbox for compatibility with Docker/CI.
HOME /tmp Sets a writable home directory for Chrome in restricted environments.
XDG_CONFIG_HOME /tmp/.config Sets a writable config directory to avoid permission errors.

Testing

See CONTRIBUTING.md for instructions on running the test suite, coverage, and other QA targets.

License

MIT License. See LICENSE for details.

ycchuang99/laravel-pdf-chrome-driver 适用场景与选型建议

ycchuang99/laravel-pdf-chrome-driver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「pdf」 「driver」 「laravel」 「chrome」 「headless-chrome」 「chrome-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ycchuang99/laravel-pdf-chrome-driver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ycchuang99/laravel-pdf-chrome-driver 我们能提供哪些服务?
定制开发 / 二次开发

基于 ycchuang99/laravel-pdf-chrome-driver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 23
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-12