Skip to main content
This guide is for Laravel applications.
You may generate PDFs in Laravel Cloud with Cloudflare’s Browser Rendering API. To get started, generate a Cloudflare API token that has the Account.Browser Rendering permission and locate your Account ID from your Cloudflare dashboard URL.

Using Laravel PDF

Spatie’s Laravel PDF package provides a convenient wrapper around Cloudflare’s Browser Rendering API through its built-in Cloudflare driver. Your instances don’t need Node.js or a Chrome binary. First, install the package with Composer:
Then, add the following environment variables to your Cloud environment’s environment variable settings:
Once you configure these variables, you may generate PDFs using the Pdf facade. For example, the following controller method renders a view as a PDF and streams it as a download to the browser:
For more information on available options such as custom paper sizes, margins, headers, and footers, see the Laravel PDF documentation.

Using Laravel Cashier with Laravel PDF

Cashier’s default invoice PDF renderer uses Dompdf, which does not work in Laravel Cloud. To generate Cashier invoices on Cloud, install Spatie’s Laravel PDF package and configure the Cloudflare environment variables as described in Using Laravel PDF:
Then, set Cashier to use its built-in Laravel PDF invoice renderer by adding the following environment variable to your Cloud environment’s environment variable settings:
Cashier resolves this renderer at runtime and uses Spatie Laravel PDF to generate invoice downloads.

Manual usage

If you prefer to call the Cloudflare API directly without an additional dependency, add a cloudflare entry to your services.php config file:
Next, set these environment variables in your Cloud environment’s environment variable settings. Now you may call the Cloudflare PDF API using Laravel’s built-in Http facade. The following controller method renders a view to HTML and streams the response to the browser as a downloadable PDF: