Configuration | laravel-pdf | Spatie

 SPATIE

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

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-pdf](https://spatie.be/docs/laravel-pdf/v1)  Advanced-usage  Configuration

 Version   v2   v1

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

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

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

- [ Creating PDFs ](https://spatie.be/docs/laravel-pdf/v1/basic-usage/creating-pdfs)
- [ Responding with PDFs ](https://spatie.be/docs/laravel-pdf/v1/basic-usage/responding-with-pdfs)
- [ Formatting PDFs ](https://spatie.be/docs/laravel-pdf/v1/basic-usage/formatting-pdfs)
- [ Saving PDFs to disks ](https://spatie.be/docs/laravel-pdf/v1/basic-usage/saving-pdfs-to-disks)
- [ Testing PDFs ](https://spatie.be/docs/laravel-pdf/v1/basic-usage/testing-pdfs)
- [ Setting defaults ](https://spatie.be/docs/laravel-pdf/v1/basic-usage/setting-defaults)

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

- [ Configuration ](https://spatie.be/docs/laravel-pdf/v1/advanced-usage/configuration)
- [ Creating PDFs with multiple pages ](https://spatie.be/docs/laravel-pdf/v1/advanced-usage/creating-pdfs-with-multiple-pages)
- [ Customizing Browsershot ](https://spatie.be/docs/laravel-pdf/v1/advanced-usage/customizing-browsershot)
- [ Generating PDFs on AWS Lambda ](https://spatie.be/docs/laravel-pdf/v1/advanced-usage/generating-pdfs-on-aws-lambda)
- [ Using Tailwind ](https://spatie.be/docs/laravel-pdf/v1/advanced-usage/using-tailwind)
- [ Extending with Macros ](https://spatie.be/docs/laravel-pdf/v1/advanced-usage/extending-with-macros)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-pdf                                                                                                                                                                                                                                    `

Configuration
=============

###  On this page

1. [ Publishing the Configuration File ](#content-publishing-the-configuration-file)
2. [ Configuration Options ](#content-configuration-options)
3. [ Environment Variables ](#content-environment-variables)
4. [ Overriding Configuration ](#content-overriding-configuration)

Laravel PDF supports configuration-based customization of Browsershot settings, allowing you to set default options that apply to all PDF generation in your application.

Publishing the Configuration File
-----------------------------------------------------------------------------------------------------------------------------------------------------------

To publish the configuration file, run:

```
php artisan vendor:publish --tag=pdf-config
```

This will create a `config/laravel-pdf.php` file in your application.

Configuration Options
-----------------------------------------------------------------------------------------------------------------------

The configuration file provides several sections for customizing Browsershot behavior:

### Binary Paths

Configure paths to Node.js, npm, Chrome, and other binaries:

```
'browsershot' => [
    'node_binary' => env('LARAVEL_PDF_NODE_BINARY'),
    'npm_binary' => env('LARAVEL_PDF_NPM_BINARY'),
    'include_path' => env('LARAVEL_PDF_INCLUDE_PATH'),
    'chrome_path' => env('LARAVEL_PDF_CHROME_PATH'),
    'node_modules_path' => env('LARAVEL_PDF_NODE_MODULES_PATH'),
    'bin_path' => env('LARAVEL_PDF_BIN_PATH'),
    'temp_path' => env('LARAVEL_PDF_TEMP_PATH'),
    'write_options_to_file' => env('LARAVEL_PDF_WRITE_OPTIONS_TO_FILE', false),
    'no_sandbox' => env('LARAVEL_PDF_NO_SANDBOX', false),
],
```

Environment Variables
-----------------------------------------------------------------------------------------------------------------------

You can also use environment variables to configure PDF generation:

```
LARAVEL_PDF_NODE_BINARY=/usr/local/bin/node
LARAVEL_PDF_NPM_BINARY=/usr/local/bin/npm
LARAVEL_PDF_INCLUDE_PATH=/usr/local/bin
LARAVEL_PDF_CHROME_PATH=/usr/bin/google-chrome-stable
LARAVEL_PDF_NODE_MODULES_PATH=/path/to/node_modules
LARAVEL_PDF_BIN_PATH=/usr/local/bin
LARAVEL_PDF_TEMP_PATH=/tmp
LARAVEL_PDF_WRITE_OPTIONS_TO_FILE=true
LARAVEL_PDF_NO_SANDBOX=true
```

Overriding Configuration
--------------------------------------------------------------------------------------------------------------------------------

Configuration defaults can still be overridden on a per-PDF basis using the `withBrowsershot()` method:

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

// This PDF will use the configuration defaults plus the scale override
Pdf::view('invoice', ['invoice' => $invoice])
    ->withBrowsershot(function (Browsershot $browsershot) {
        $browsershot->scale(0.8);
    })
    ->save('invoice.pdf');
```

The `withBrowsershot()` closure runs after configuration defaults are applied, allowing you to modify or override any setting.
