Installation &amp; setup | 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)  Installation &amp; setup

 Version   v1      

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

  Installation &amp; setup    
- [ 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)

 Installation &amp; setup
========================

###  On this page 

1. [ Choosing a driver ](#content-choosing-a-driver)
2. [ Package skills ](#content-package-skills)
3. [ Configuration ](#content-configuration)

Install the package with Go:

```
go get github.com/spatie/laravel-pdf-go@v0.1.0
```

Add it to your application's `bootstrap/app.go` options:

```
import (
    pdf "github.com/spatie/laravel-pdf-go"
    laravel "go.laravel.com"
)

func Options() laravel.Options {
    return laravel.Options{
        Packages: []laravel.Package{pdf.New()},
    }
}
```

Installing the module does not activate it. Keep the rest of your application's options when adding the package. `pdf.From(ctx)` resolves the factory in that application. Handlers can pass their `*web.Request` as the context.

Choosing a driver
-----------------------------------------------------------------------------------------------------------

Set `LARAVEL_PDF_DRIVER` to `browsershot`, `cloudflare`, `gotenberg`, `weasyprint`, `dompdf` or `chrome`. Follow the [requirements](requirements) for that driver.

### Browsershot driver (default)

Install Node 22.12+, Puppeteer 23+ and Chrome. Go uses the released Browsershot Go module with its embedded Node runner rather than the PHP package. See [customizing Browsershot](drivers/customizing-browsershot).

### Cloudflare driver

```
LARAVEL_PDF_DRIVER=cloudflare
CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_API_TOKEN=your-api-token
```

### Gotenberg driver

```
LARAVEL_PDF_DRIVER=gotenberg
GOTENBERG_URL=http://gotenberg:3000
```

Optional `GOTENBERG_USERNAME` and `GOTENBERG_PASSWORD` enable HTTP Basic authentication.

### WeasyPrint driver

Set `LARAVEL_PDF_DRIVER=weasyprint`. `LARAVEL_PDF_WEASYPRINT_BINARY` defaults to `weasyprint` on PATH. Other options belong in `Config.WeasyPrint`.

### DOMPDF driver

Set `LARAVEL_PDF_DRIVER=dompdf` and `LARAVEL_PDF_DOMPDF_AUTOLOAD=/absolute/path/vendor/autoload.php`. This is the only bundled driver requiring a PHP runtime.

### Chrome driver

Set `LARAVEL_PDF_DRIVER=chrome`. Use `LARAVEL_PDF_CHROME_BINARY` for a specific browser path. Only disable the browser sandbox in an appropriately isolated environment.

Package skills
--------------------------------------------------------------------------------------------------

This repository includes package-development and version-matched Laravel Go skills in `.agents/skills`. Laravel Boost's PHP package installer is not used by this Go module.

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

There is no config-publishing command in Go. Pass callbacks after environment defaults:

```
pdf.New(func(c *pdf.Config) {
    c.Driver = "chrome"
    c.Defaults = func(b *pdf.Builder) {
        b.Format(pdf.A4).Margins(15, 15, 15, 15, pdf.Millimeter)
    }
})
```

See [driver configuration](drivers/configuration) for all environment settings and replacement contracts. Outside Laravel, `pdf.NewFactory(pdf.Config{...})` can generate HTML and save local files. Framework views, disks, queues and the default cache require an application context.

 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)
