PHPackages                             lastdino/chrome-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. lastdino/chrome-laravel

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

lastdino/chrome-laravel
=======================

Laravel integration for chrome-php/chrome with a service provider and fluent manager for rendering PDFs, etc.

v0.1.3(1mo ago)02012MITPHPPHP ^8.2

Since Dec 8Pushed 1mo agoCompare

[ Source](https://github.com/lastdino/chrome-laravel)[ Packagist](https://packagist.org/packages/lastdino/chrome-laravel)[ RSS](/packages/lastdino-chrome-laravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (2)

Chrome Laravel Integration (chrome-php)

English | 日本語

---

About

This Laravel 12 application demonstrates rendering web pages to PDF using Headless Chrome via the chrome-php/chrome library. It includes a small integration package at packages/lastdino/chrome-laravel that provides a ChromeManager service and a Chrome facade.

Features

- Render any URL to PDF using a real Chrome instance (headless)
- Render raw HTML to PDF via setHtml
- Sensible defaults (e.g., printBackground: true)
- Configure Chrome binary path, headless mode, custom flags, and timeouts
- Clean shutdown to avoid zombie processes
- Per-call option overrides merged with config defaults

Requirements

- PHP 8.4+
- Laravel 12
- Chrome/Chromium binary available on the host
- composer dependency: chrome-php/chrome

Install

1. Package installation (if using in your own project)

    - composer require lastdino/chrome-laravel
2. Backend dependencies

    - composer install
3. Environment setup

    - Copy .env.example to .env
    - php artisan key:generate
4. Frontend (optional)

    - npm install
    - npm run dev

Configuration

The package configuration lives at packages/lastdino/chrome-laravel/src/config/chrome.php. Publish it to your app config with:

```
php artisan vendor:publish --provider="LastDino\ChromeLaravel\ChromeServiceProvider" --tag=chrome-config --no-interaction

```

Key settings in config/chrome.php:

- binary: read from env CHROME\_BINARY (optional absolute path to Chrome/Chromium)
- headless: read from env CHROME\_HEADLESS, one of: new | old | disabled (default: new)
- args: extra flags to pass to Chrome process (array, edit in config if needed)
- connection\_timeout, send\_timeout, idle\_timeout: timeouts in seconds
- pdf: default PDF options (merged with per-call overrides)

Usage

Use the Chrome facade to render to a temporary PDF file path. Two entry points are available:

1. pdf(string $url, array $options = \[\])
2. pdfFromHtml(string $html, array $options = \[\])

Code (PHP):

```
use LastDino\ChromeLaravel\Facades\Chrome;

// 1) From URL
public function downloadFromUrl()
{
    $url = route('home');
    $tmpPath = Chrome::pdf($url, [
        'printBackground' => true,
        'landscape' => true,
    ]);

    return response()->download($tmpPath, 'page.pdf')->deleteFileAfterSend();
}

// 2) From raw HTML
public function downloadFromHtml()
{
    $html = view('pdf.invoice', ['invoice' => 123])->render();
    $tmpPath = Chrome::pdfFromHtml($html, [
        'scale' => 0.9,
    ]);

    return response()->download($tmpPath, 'invoice.pdf')->deleteFileAfterSend();
}

```

Options

- Options map to Chrome DevTools Page.printToPDF parameters. Common ones:

    - printBackground (bool)
    - landscape (bool)
    - scale (float)
    - pageRanges (string)
    - paperWidth / paperHeight (inches)
    - marginTop / marginBottom / marginLeft / marginRight (inches)
    - displayHeaderFooter, headerTemplate, footerTemplate
- Per-call options are merged over the defaults defined in config('chrome.pdf'). Testing
- php artisan test

Code Style

- vendor/bin/pint --dirty

Troubleshooting

- Frontend changes not visible? Try: npm run dev, npm run build, or composer run dev
- Ensure Chrome/Chromium exists on the system; set CHROME\_BINARY in .env if auto-detection fails
- If you see timeouts, increase values in config/chrome.php (connection\_timeout/send\_timeout/idle\_timeout)
- In restricted environments, you may need flags like --no-sandbox in config('chrome.args')

License

MIT

---

README (日本語)

概要

本プロジェクトは、chrome-php/chrome を用いて Headless Chrome により Web ページを PDF 化する Laravel 12 アプリケーションの例です。packages/lastdino/chrome-laravel 配下に、ChromeManager サービスと Chrome ファサードを提供する軽量な統合パッケージが含まれています。

特長

- 実際の Chrome（ヘッドレス）で任意の URL を PDF にレンダリング
- 生の HTML を setHtml で PDF 化
- 使いやすい既定値（例: printBackground: true）
- Chrome バイナリパス、ヘッドレス動作、カスタムフラグ、各種タイムアウトを設定可能
- プロセスを確実に終了し、ゾンビプロセスを回避
- 呼び出し毎のオプションで設定の既定値を上書き可能

必要条件

- PHP 8.4+
- Laravel 12
- システム上に Chrome/Chromium がインストールされていること
- 依存パッケージ: chrome-php/chrome

インストール手順

1. パッケージのインストール（ご自身のプロジェクトに導入する場合）

    - composer require lastdino/chrome-laravel
2. バックエンド依存関係

    - composer install
3. 環境設定

    - .env.example を .env にコピー
    - php artisan key:generate
4. フロントエンド（任意）

    - npm install
    - npm run dev

設定

設定ファイルは packages/lastdino/chrome-laravel/src/config/chrome.php にあります。 アプリ側へ公開するには次のコマンドを実行します。

```
php artisan vendor:publish --provider="LastDino\ChromeLaravel\ChromeServiceProvider" --tag=chrome-config --no-interaction

```

主な設定項目（config/chrome.php）:

- binary: 環境変数 CHROME\_BINARY から読み込み（Chrome/Chromium のパス・任意）
- headless: 環境変数 CHROME\_HEADLESS（new | old | disabled、既定 new）
- args: Chrome 起動フラグ（配列。必要に応じて設定ファイルで編集）
- connection\_timeout / send\_timeout / idle\_timeout: タイムアウト（秒）
- pdf: 既定の PDF オプション（呼び出し時の指定で上書き可能）

使い方

Chrome ファサードを使って PDF を生成します。利用可能な 2 つの入口関数:

1. pdf(string $url, array $options = \[\])
2. pdfFromHtml(string $html, array $options = \[\])

コード（PHP）:

```
use LastDino\ChromeLaravel\Facades\Chrome;

// 1) URL から
public function downloadFromUrl()
{
    $url = route('home');
    $tmpPath = Chrome::pdf($url, [
        'printBackground' => true,
        'landscape' => true,
    ]);

    return response()->download($tmpPath, 'page.pdf')->deleteFileAfterSend();
}

// 2) 生の HTML から
public function downloadFromHtml()
{
    $html = view('pdf.invoice', ['invoice' => 123])->render();
    $tmpPath = Chrome::pdfFromHtml($html, [
        'scale' => 0.9,
    ]);

    return response()->download($tmpPath, 'invoice.pdf')->deleteFileAfterSend();
}

```

オプション

- オプションは Chrome DevTools の Page.printToPDF に対応します。代表例:

    - printBackground（bool）
    - landscape（bool）
    - scale（float）
    - pageRanges（string）
    - paperWidth / paperHeight（インチ）
    - marginTop / marginBottom / marginLeft / marginRight（インチ）
    - displayHeaderFooter, headerTemplate, footerTemplate
- 呼び出し時のオプションは config('chrome.pdf') の既定値にマージされます。 テスト
- php artisan test

コーディング規約

- vendor/bin/pint --dirty を実行して整形してください

トラブルシューティング

- フロントエンドの変更が反映されない場合: npm run dev / npm run build / composer run dev（定義時）
- システムに Chrome/Chromium が存在することを確認し、自動検出に失敗する場合は .env の CHROME\_BINARY を設定してください
- タイムアウトが発生する場合は config/chrome.php の connection\_timeout / send\_timeout / idle\_timeout を増やしてください
- 制限のある環境では --no-sandbox などのフラグを config('chrome.args') に追加してください

ライセンス

MIT

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~36 days

Total

4

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a91f54a5ec14785c7b8531214937c76ec0ec0874736a709c2bd973fdb9e619b?d=identicon)[lastdino](/maintainers/lastdino)

---

Top Contributors

[![lastdino](https://avatars.githubusercontent.com/u/87484368?v=4)](https://github.com/lastdino "lastdino (6 commits)")

---

Tags

laravelpdfheadlesschromechrome-php

### Embed Badge

![Health badge](/badges/lastdino-chrome-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/lastdino-chrome-laravel/health.svg)](https://phpackages.com/packages/lastdino-chrome-laravel)
```

###  Alternatives

[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k87.6M278](/packages/barryvdh-laravel-dompdf)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[chrome-php/chrome

Instrument headless chrome/chromium instances from PHP

2.6k4.5M64](/packages/chrome-php-chrome)[elibyy/tcpdf-laravel

tcpdf support for Laravel 6, 7, 8, 9, 10, 11

3542.7M5](/packages/elibyy-tcpdf-laravel)[spiritix/php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome

153472.0k3](/packages/spiritix-php-chrome-html2pdf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
