Introduction | 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)  Introduction

 Version   v1      

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

  Introduction    
- [ 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)

  Laravel-pdf-go 
================

 Generate PDFs in Laravel Go applications 

### Useful links

- [Repository](https://github.com/spatie/laravel-pdf-go)
- [Discussions](https://github.com/spatie/laravel-pdf-go/discussions)

Introduction
------------

This package provides a simple way to create PDFs in Laravel Go apps. It uses a driver-based architecture, so you can choose between different PDF generation backends:

- Browsershot, the default, uses [Browsershot Go](https://github.com/spatie/browsershot-go) to generate PDFs with Chromium.
- Gotenberg uses [Gotenberg](https://gotenberg.dev), a Docker-based API with headless Chromium.
- Cloudflare uses [Cloudflare's Browser Run API](https://developers.cloudflare.com/browser-run/) with a simple HTTP call.
- WeasyPrint runs the [WeasyPrint](https://doc.courtbouillon.org/weasyprint/stable/) binary, with CSS Paged Media support.
- DOMPDF calls [dompdf/dompdf](https://github.com/dompdf/dompdf) through an embedded PHP bridge. This driver still requires PHP and a Composer autoloader.
- Chrome talks directly to a local Chrome or Chromium executable through the DevTools protocol.

The browser drivers support modern CSS features like grid and flexbox, including compiled Tailwind styles. WeasyPrint supports CSS Paged Media and repeating headers and footers. DOMPDF supports CSS 2.1 and some CSS 3 properties for simpler documents.

Here's a quick example:

```
err := pdf.From(ctx).
    View("pdf/invoice", map[string]any{"Number": 42}).
    Format(pdf.A4).
    Save(ctx, "invoice.pdf")
```

This renders the application's view with the given data and saves it as a PDF. Import the package as `pdf "github.com/spatie/laravel-pdf-go"` in the examples throughout these docs. Handle returned errors in your application.

You can also return the PDF from a handler:

```
func DownloadInvoice(r *web.Request) *web.Response {
    return pdf.From(r).View("pdf/invoice", invoice).
        Download("invoice.pdf").Response(r)
}
```

Or queue generation for background processing:

```
id, err := pdf.From(ctx).View("pdf/invoice", invoice).
    Disk("private").SaveQueued(ctx, "invoices/42.pdf")
```

Drivers, defaults, cache, encryption and job construction are customizable. There are no package-owned database models or profile classes. Go uses explicit application registration rather than PHP facades or auto-discovery. See [installation and setup](installation-setup) and [testing PDFs](basic-usage/testing-pdfs).

 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)
