Configuration | laravel-pdf-go | Spatie       

 SPATIE  

laravel-pdf-go
==============

spatie.be/open-source

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

 Version   v1      

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

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

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

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

Drivers
-------

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

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

- [ Creating PDFs with multiple pages ](https://spatie.be/docs/laravel-pdf-go/v1/advanced-usage/creating-pdfs-with-multiple-pages)
- [ Using Tailwind ](https://spatie.be/docs/laravel-pdf-go/v1/advanced-usage/using-tailwind)
- [ Extending with Macros ](https://spatie.be/docs/laravel-pdf-go/v1/advanced-usage/extending-with-macros)
- [ Waiting for readiness ](https://spatie.be/docs/laravel-pdf-go/v1/advanced-usage/waiting-for-readiness)
- [ Caching PDFs ](https://spatie.be/docs/laravel-pdf-go/v1/advanced-usage/caching-pdfs)

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

###  On this page 

1. [ Configuration callbacks ](#content-configuration-callbacks)
2. [ Selecting a driver ](#content-selecting-a-driver)
3. [ Browsershot configuration ](#content-browsershot-configuration)
4. [ Cloudflare configuration ](#content-cloudflare-configuration)
5. [ Chrome configuration ](#content-chrome-configuration)
6. [ Gotenberg configuration ](#content-gotenberg-configuration)
7. [ WeasyPrint configuration ](#content-weasyprint-configuration)
8. [ DOMPDF configuration ](#content-dompdf-configuration)
9. [ Environment variables ](#content-environment-variables)
10. [ Runtime driver switching ](#content-runtime-driver-switching)

Configuration callbacks
-----------------------------------------------------------------------------------------------------------------------------

Go does not publish a PHP configuration file. Pass callbacks to `pdf.New`. Environment defaults are read first, and callbacks run afterward in the order supplied:

```
pdf.New(func(c *pdf.Config) {
    c.Driver = "chrome"
    c.Chrome.Timeout = time.Minute
})
```

Selecting a driver
--------------------------------------------------------------------------------------------------------------

The default is `browsershot`. Available names are `browsershot`, `chrome`, `cloudflare`, `gotenberg`, `weasyprint` and `dompdf`. Unknown default names stop registration with an error. Register your own name with `Config.Drivers`.

Browsershot configuration
-----------------------------------------------------------------------------------------------------------------------------------

See [customizing Browsershot](customizing-browsershot). Browsershot Go retains a Node/Puppeteer runner. Its binary, module, include-path, temporary-directory and runner settings remain configurable. The separate Chrome driver is Go-native.

Cloudflare configuration
--------------------------------------------------------------------------------------------------------------------------------

`Config.Cloudflare` accepts `Token`, `AccountID`, optional `Endpoint` and an injectable `*http.Client`. The endpoint override supports proxies and local integration tests. Account and token are required at render time.

Chrome configuration
--------------------------------------------------------------------------------------------------------------------

`Config.Chrome` accepts `Binary`, `NoSandbox`, `Timeout`, `UserDataDir`, `Flags map[string]any` and `Environment []string`. The overall timeout defaults to 30 seconds. Environment entries use `NAME=value` strings. Flags follow chromedp's accepted types. Do not disable the sandbox for untrusted documents.

Gotenberg configuration
-----------------------------------------------------------------------------------------------------------------------------

`Config.Gotenberg` accepts `URL`, `Username`, `Password` and an injectable HTTP client. The URL defaults to `http://localhost:3000`. The client defaults to a 60-second timeout. Non-2xx responses return `*pdf.HTTPError`, with the status but without provider bodies that might contain sensitive HTML.

WeasyPrint configuration
--------------------------------------------------------------------------------------------------------------------------------

`Config.WeasyPrint` accepts `Binary`, `Timeout` and `Arguments []string`. Registration defaults to a 10-second timeout. Standalone zero-value drivers use 30 seconds. Arguments are passed directly to the executable, never through a shell. Only accept arguments from trusted application configuration.

DOMPDF configuration
--------------------------------------------------------------------------------------------------------------------

`Config.DOMPDF` accepts `PHP`, `Autoload`, `RemoteEnabled`, `Chroot`, `FontDir`, `FontCache` and `Timeout`. The executable defaults to `php`. An absolute Composer autoloader path is required. Remote resources are disabled by default. The font cache defaults to the configured font directory.

Environment variables
-----------------------------------------------------------------------------------------------------------------------

VariableDefault`LARAVEL_PDF_DRIVER``browsershot``LARAVEL_PDF_CACHE_AUTOMATIC``false``LARAVEL_PDF_CACHE_TTL``86400` seconds`LARAVEL_PDF_CACHE_STORE`Application default`LARAVEL_PDF_NODE_BINARY`Node on PATH`LARAVEL_PDF_NPM_BINARY`npm on PATH`LARAVEL_PDF_CHROME_PATH`Puppeteer browser discovery`LARAVEL_PDF_NODE_MODULES_PATH`Node module resolution`LARAVEL_PDF_INCLUDE_PATH`Inherited PATH`LARAVEL_PDF_BIN_PATH`Embedded Browsershot runner`LARAVEL_PDF_TEMP_PATH`OS temporary directory`LARAVEL_PDF_WRITE_OPTIONS_TO_FILE``true``LARAVEL_PDF_NO_SANDBOX``false``LARAVEL_PDF_CHROME_BINARY`Browser discovery`LARAVEL_PDF_CHROME_NO_SANDBOX``false``LARAVEL_PDF_CHROME_TIMEOUT``30000` milliseconds`LARAVEL_PDF_CHROME_USER_DATA_DIR`Temporary profile`CLOUDFLARE_API_TOKEN`None`CLOUDFLARE_ACCOUNT_ID`None`GOTENBERG_URL``http://localhost:3000``GOTENBERG_USERNAME`None`GOTENBERG_PASSWORD`None`LARAVEL_PDF_WEASYPRINT_BINARY``weasyprint``LARAVEL_PDF_PHP_BINARY``php``LARAVEL_PDF_DOMPDF_AUTOLOAD`None`LARAVEL_PDF_DOMPDF_REMOTE_ENABLED``false``LARAVEL_PDF_DOMPDF_CHROOT`DOMPDF default`LARAVEL_PDF_DOMPDF_FONT_DIR`DOMPDF default`LARAVEL_PDF_DOMPDF_FONT_CACHE`Font directoryRuntime driver switching
--------------------------------------------------------------------------------------------------------------------------------

```
err := pdf.From(ctx).HTML("<h1>Invoice</h1>").
    Driver("gotenberg").Save(ctx, "invoice.pdf")
```

`SetDriver(instance)` supplies a driver for one document. Register a named driver in configuration when it must also work in queued jobs. Use `Config.Defaults` for formatting, `Config.Cache` for cache replacement, `Config.Encrypter` for encryption replacement and `Config.JobFactory` for a custom queued job type. Do not register a second factory service to override the package in Laravel Go v0.1.0.

 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)
