Customizing Browsershot | 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)  Drivers  Customizing Browsershot

 Version   v1      

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

  Customizing Browsershot    
- [ 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)

 Customizing Browsershot
=======================

###  On this page 

1. [ Configuration-Based Customization ](#content-configuration-based-customization)
2. [ Per-PDF Customization ](#content-per-pdf-customization)
3. [ Advanced Browsershot Configuration ](#content-advanced-browsershot-configuration)
4. [ Testing your Browsershot configuration ](#content-testing-your-browsershot-configuration)

When using the Browsershot driver, you can customize the underlying [Browsershot](https://spatie.be/docs/browsershot) PDF options. This is only applicable when using the `browsershot` driver.

Configuration-Based Customization
-----------------------------------------------------------------------------------------------------------------------------------------------------------

For settings that apply to all PDFs in your application, use the [configuration](configuration) to set defaults. This is especially useful for binary paths.

Use `PhpBridgeDriver::config` for executable paths, sandbox settings and the remote browser instance. The bridge supports `node_binary`, `npm_binary`, `include_path`, `chrome_path`, `node_modules_path`, `bin_path`, `temp_path`, `write_options_to_file`, `no_sandbox`, and `remote_instance` (`host` and `port`).

Per-PDF Customization
-----------------------------------------------------------------------------------------------------------------------

You can customize the browser options for individual PDFs by calling the `browser_options` method. This method accepts a closure that receives the options as its only argument.

Here's an example of how you can set Browsershot's scale option:

```
use serde_json::json;

pdf.view("test", json!({}))
    .browser_options(|options| {
        options.insert("scale".into(), json!(0.5));
    })
    .save(target_path).await?;
```

The options override the mapped PDF defaults, allowing you to modify or override PDF settings on a per-PDF basis. The closure runs immediately and stores serializable data, not a captured callback.

Advanced Browsershot Configuration
--------------------------------------------------------------------------------------------------------------------------------------------------------------

For browser operations not exposed by the bridge, implement an application `PdfDriver`, or extend the reviewed bridge. Keep local assets available to the renderer without disabling browser security. Do not use shell interpolation or evaluate serialized executable code. Treat disabled browser security as a worker-isolation decision, not a per-request default.

Testing your Browsershot configuration
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

When faking PDF generation in your tests, you can assert that your `browser_options` configuration was applied using the `assert_browser_options` method. Head over to [Testing PDFs](../basic-usage/testing-pdfs) to learn more. Default-builder options are cloned into each PDF.

 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)
