Using the Chrome driver | laravel-pdf | Spatie

 SPATIE

  Laravel PDF
==============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-pdf](https://spatie.be/docs/laravel-pdf/v2)  Drivers  Using the Chrome driver

 Version   v2   v1

 Other versions for crawler [v2](https://spatie.be/docs/laravel-pdf/v2) [v1](https://spatie.be/docs/laravel-pdf/v1)

  Using the Chrome driver
- [ Introduction ](https://spatie.be/docs/laravel-pdf/v2/introduction)
- [ Support us ](https://spatie.be/docs/laravel-pdf/v2/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-pdf/v2/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-pdf/v2/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-pdf/v2/questions-issues)
- [ Alternatives ](https://spatie.be/docs/laravel-pdf/v2/alternatives)
- [ Changelog ](https://spatie.be/docs/laravel-pdf/v2/changelog)
- [ About us ](https://spatie.be/docs/laravel-pdf/v2/about-us)

Basic usage
-----------

- [ Creating PDFs ](https://spatie.be/docs/laravel-pdf/v2/basic-usage/creating-pdfs)
- [ Responding with PDFs ](https://spatie.be/docs/laravel-pdf/v2/basic-usage/responding-with-pdfs)
- [ Formatting PDFs ](https://spatie.be/docs/laravel-pdf/v2/basic-usage/formatting-pdfs)
- [ Saving PDFs to disks ](https://spatie.be/docs/laravel-pdf/v2/basic-usage/saving-pdfs-to-disks)
- [ Attaching PDFs to mails ](https://spatie.be/docs/laravel-pdf/v2/basic-usage/attaching-pdfs-to-mails)
- [ Queued PDF generation ](https://spatie.be/docs/laravel-pdf/v2/basic-usage/queued-pdf-generation)
- [ Testing PDFs ](https://spatie.be/docs/laravel-pdf/v2/basic-usage/testing-pdfs)
- [ Setting defaults ](https://spatie.be/docs/laravel-pdf/v2/basic-usage/setting-defaults)

Drivers
-------

- [ Configuration ](https://spatie.be/docs/laravel-pdf/v2/drivers/configuration)
- [ Customizing Browsershot ](https://spatie.be/docs/laravel-pdf/v2/drivers/customizing-browsershot)
- [ Using the Cloudflare driver ](https://spatie.be/docs/laravel-pdf/v2/drivers/using-the-cloudflare-driver)
- [ Using the DOMPDF driver ](https://spatie.be/docs/laravel-pdf/v2/drivers/using-the-dompdf-driver)
- [ Generating PDFs on AWS Lambda ](https://spatie.be/docs/laravel-pdf/v2/drivers/generating-pdfs-on-aws-lambda)
- [ Using the Chrome driver ](https://spatie.be/docs/laravel-pdf/v2/drivers/using-the-chrome-driver)
- [ Using the Gotenberg driver ](https://spatie.be/docs/laravel-pdf/v2/drivers/using-the-gotenberg-driver)
- [ Using the WeasyPrint driver ](https://spatie.be/docs/laravel-pdf/v2/drivers/using-the-weasyprint-driver)
- [ Custom drivers ](https://spatie.be/docs/laravel-pdf/v2/drivers/custom-drivers)

Advanced usage
--------------

- [ Creating PDFs with multiple pages ](https://spatie.be/docs/laravel-pdf/v2/advanced-usage/creating-pdfs-with-multiple-pages)
- [ Using Tailwind ](https://spatie.be/docs/laravel-pdf/v2/advanced-usage/using-tailwind)
- [ Extending with Macros ](https://spatie.be/docs/laravel-pdf/v2/advanced-usage/extending-with-macros)

 Using the Chrome driver
=======================

###  On this page

1. [ Getting started ](#content-getting-started)
2. [ Supported options ](#content-supported-options)
3. [ Configuration ](#content-configuration)
4. [ Using Chrome for specific PDFs only ](#content-using-chrome-for-specific-pdfs-only)
5. [ Limitations ](#content-limitations)

The Chrome driver uses [chrome-php/chrome](https://github.com/chrome-php/chrome) to generate PDFs directly from PHP. It is a good fit when you want a Chromium-based driver without bringing in Node.js or Puppeteer.

Getting started
-----------------------------------------------------------------------------------------------------

1. Install the Chrome package:

```
composer require chrome-php/chrome
```

2. Make sure Chrome or Chromium is installed on the machine that generates the PDFs.

The upstream library requires a Chrome/Chromium 65+ executable. It can auto-discover the browser in common locations, but you can also configure the binary path explicitly.

3. Set the driver in your `.env` file:

```
LARAVEL_PDF_DRIVER=chrome
```

If Chrome cannot be auto-discovered, also set the browser path:

```
LARAVEL_PDF_CHROME_BINARY=/usr/bin/google-chrome-stable
```

That's it. Your existing PDF code will now use the Chrome driver:

```
use Spatie\LaravelPdf\Facades\Pdf;

Pdf::view('pdfs.invoice', ['invoice' => $invoice])
    ->format('a4')
    ->save('invoice.pdf');
```

Supported options
-----------------------------------------------------------------------------------------------------------

The Chrome driver supports the following PDF options:

- `format()` — Paper format (a4, letter, legal, etc.)
- `paperSize()` — Custom paper dimensions
- `margins()` — Page margins
- `landscape()` / `orientation()` — Page orientation
- `scale()` — Page rendering scale
- `pageRanges()` — Specific pages to include
- `headerView()` / `headerHtml()` — Page headers
- `footerView()` / `footerHtml()` — Page footers

Configuration
-----------------------------------------------------------------------------------------------

The Chrome driver accepts these configuration options in `config/laravel-pdf.php`:

```
'chrome' => [
    'chrome_binary' => env('LARAVEL_PDF_CHROME_BINARY'),
    'no_sandbox' => env('LARAVEL_PDF_CHROME_NO_SANDBOX', false),
    'startup_timeout' => env('LARAVEL_PDF_CHROME_STARTUP_TIMEOUT', 30),
    'timeout' => env('LARAVEL_PDF_CHROME_TIMEOUT', 30000),
    'operation_timeout' => env('LARAVEL_PDF_CHROME_OPERATION_TIMEOUT', 5000),
    'user_data_dir' => env('LARAVEL_PDF_CHROME_USER_DATA_DIR'),
    'custom_flags' => [],
    'env_variables' => [],
],
```

- **chrome\_binary**: The path to the Chrome or Chromium executable. If omitted, the driver will try to auto-discover it.
- **no\_sandbox**: Disables Chrome's sandbox. This is sometimes needed in Docker or restricted server environments.
- **startup\_timeout**: Maximum time in seconds to wait for Chrome to start.
- **timeout**: Maximum time in milliseconds to wait when setting the page HTML.
- **operation\_timeout**: Maximum time in milliseconds to wait for Chrome PDF operations like binary output and file saves.
- **user\_data\_dir**: Custom Chrome profile directory.
- **custom\_flags**: Additional Chrome command-line flags.
- **env\_variables**: Environment variables passed to the Chrome process.

Using Chrome for specific PDFs only
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

If you want to use another driver as your default but switch to Chrome for specific PDFs, use the `driver` method:

```
use Spatie\LaravelPdf\Facades\Pdf;

Pdf::view('pdfs.invoice', ['invoice' => $invoice])
    ->driver('chrome')
    ->format('a4')
    ->save('invoice.pdf');
```

Limitations
-----------------------------------------------------------------------------------------

- The Chrome driver requires both the `chrome-php/chrome` package and a local Chrome or Chromium executable. It does not download or bundle a browser for you.
- In Docker or other locked-down environments, you may need to enable `no_sandbox`.
- This driver only documents and exposes the options supported by Laravel PDF. If you need deeper Chromium customization, use the Browsershot driver instead.
- The `tagged()`, `withBrowsershot()` and `onLambda()` methods have no effect when using the Chrome driver.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
