Installation &amp; setup | laravel-pdf-rust | Spatie       

 SPATIE  

laravel-pdf-rust
================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-pdf-rust](https://spatie.be/docs/laravel-pdf-rust/v1)  Installation &amp; setup

 Version   v1      

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

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

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

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

Drivers
-------

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

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

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

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

###  On this page 

1. [ Choosing a driver ](#content-choosing-a-driver)
2. [ Registering the factory ](#content-registering-the-factory)

1. Use Rust 1.99 or newer.
2. Add the Git dependency and framework features below. The package is not published to crates.io.
3. Install a renderer's requirements.
4. Register the factory in web and worker applications using the example below.

```
[dependencies]
spatie-laravel-pdf = { git = "https://github.com/spatie/laravel-pdf-rust" }
laravel = { package = "laravel-rust", version = "=0.1.0", default-features = false, features = ["minijinja"] }
```

Enable the framework features your application needs, such as `database-sqlite` for its SQLite queue connection or `s3` for S3 storage. Database queue applications must run the framework's queue-table migration and `queue:work` worker. The package enables MiniJinja but does not choose your database or storage backend. Use a Tokio runtime for standalone async calls; framework handlers already run within one.

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

Requires Rust 1.99+. This package uses `laravel-rust` 0.1.0 with MiniJinja enabled. Set the driver on your application's default builder, select `LARAVEL_PDF_DRIVER`, or choose a registered driver with `PdfFactory::driver`. The provider reads environment defaults into `PdfConfig`; application config files can override them.

### Browsershot driver

The Browsershot driver requires PHP and the `spatie/browsershot` package:

```
composer require spatie/browsershot
```

You'll also need to install the required dependencies for Browsershot to work. You can find the instructions [here](https://spatie.be/docs/browsershot/v4/requirements).

Use `PhpBridgeDriver::new(PhpEngine::Browsershot, autoload)` to select this driver, passing your application's Composer autoloader. Other drivers do not require the Browsershot bridge.

### Cloudflare driver

The Cloudflare driver uses [Cloudflare's Browser Run API](https://developers.cloudflare.com/browser-run/) to generate PDFs. It does not require Node.js or a Chrome binary, making it a great choice for cloud-hosted apps.

To get started with Cloudflare:

1. Make sure you have a [Cloudflare account](https://dash.cloudflare.com/sign-up)
2. In the Cloudflare dashboard, go to **Manage account &gt; Account API tokens** in the sidebar
3. Click **Create Token** and create a token with the **Account.Browser Run** permission (both read and edit/write)
4. Read the account ID and API token from your application's configuration and pass them to `CloudflareDriver::new(account_id, api_token)?`.

That's it. No other dependencies are required since the Cloudflare driver uses an HTTP client.

### Gotenberg driver

The Gotenberg driver uses [Gotenberg](https://gotenberg.dev), an open-source Docker-based API with headless Chromium.

You will need a running Gotenberg instance (started with `docker run --rm -p 3000:3000 gotenberg/gotenberg:8`, or similar; see the [installation guide](https://gotenberg.dev/docs/getting-started/installation) for additional setup instructions).

Pass its URL to `GotenbergDriver::new(url)`. If you set up authentication, call `basic_auth(username, password)` on the driver.

### WeasyPrint driver

The WeasyPrint driver uses [WeasyPrint](https://doc.courtbouillon.org/weasyprint/stable/), a Python-based PDF generation tool with excellent CSS Paged Media support including repeating headers/footers and page counters.

First, install the WeasyPrint binary on your system. Follow the [installation guide](https://doc.courtbouillon.org/weasyprint/stable/first_steps.html) for your OS.

Use `WeasyPrintDriver::default()`, or set its binary, arguments, and timeout explicitly. No PHP wrapper is needed.

See [Using the WeasyPrint driver](drivers/using-the-weasyprint-driver) for more details on configuration and supported options.

### DOMPDF driver

The DOMPDF driver requires PHP, but no Node.js, Chrome or Docker.

```
composer require dompdf/dompdf
```

Use `PhpBridgeDriver::new(PhpEngine::Dompdf, autoload)`, passing your application's Composer autoloader.

Note that DOMPDF has more limited CSS support than the Chromium-based drivers. See [Using the DOMPDF driver](drivers/using-the-dompdf-driver) for details.

### Chrome driver

The Chrome driver uses the DevTools protocol to talk directly to a local Chrome or Chromium binary from Rust.

You'll need to install the Chrome/Chromium binary. You can find the instructions [here](https://www.chromium.org/getting-involved/download-chromium/). No PHP wrapper is needed.

See [Using the Chrome driver](drivers/using-the-chrome-driver) for more details on configuration, supported options, and limitations.

Registering the factory
-----------------------------------------------------------------------------------------------------------------------------

- Create a `PdfFactory` with your default builder.
- Register `service_provider(factory)` with your application. It uses package-tools to register typed settings and the factory for injection.
- Override environment-backed defaults through the application's typed `PdfConfig` section. See [configuration](drivers/configuration).

For example, with Chrome as the default:

```
use laravel::Application;
use spatie_pdf::{PdfBuilder, PdfFactory, service_provider};
use spatie_pdf::drivers::{ChromeConfig, ChromeDriver};

let pdf = PdfFactory::new(
    PdfBuilder::new(ChromeDriver::trusted_network(ChromeConfig::default())),
);

let application = Application::configure()
    .with_providers(move |providers| {
        providers.add(service_provider(pdf));
    })
    .create();
```

Driver selection and cache configuration are application-local. Without `LARAVEL_PDF_DRIVER`, the provider preserves the factory's driver. Browser renderers can load URLs and local resources; run untrusted HTML in an isolated worker with restricted filesystem and egress.

Put templates in `resources/views` as `.html` files, for example `resources/views/pdfs/invoice.html` for `pdfs.invoice`. Use Jinja expressions such as `{{ invoice.id }}` and `{% extends 'layout' %}`. Blade is not available. View rendering, storage, cache, and queue calls run inside a framework request, job, command, or `application.scope(async || { ... }).await`. Output methods are async and use Tokio; synchronous rendering engines run on blocking tasks.

 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)
