Skip to content

Instantly share code, notes, and snippets.

@driesvints
Last active January 29, 2026 18:01
Show Gist options
  • Select an option

  • Save driesvints/70162727698210274c3982ad87b37ed5 to your computer and use it in GitHub Desktop.

Select an option

Save driesvints/70162727698210274c3982ad87b37ed5 to your computer and use it in GitHub Desktop.
Cloudflare PDF generation in Laravel.
// Controller method...
public function download()
{
return response()->streamDownload(function () {
$token = config('services.cloudflare.api_token');
$accountId = config('services.cloudflare.account_id');
$cloudflareApi = 'https://api.cloudflare.com/client/v4';
echo Http::withToken($token)
->post($cloudflareApi.'/accounts/'.$accountId.'/browser-rendering/pdf', [
'html' => view('your-pdf-html')->render(),
])
->body();
}, 'file.pdf');
}
// Cloudflare config in services.php...
'cloudflare' => [
'api_token' => env('CLOUDFLARE_API_TOKEN'),
'account_id' => env('CLOUDFLARE_ACCOUNT_ID'),
],
@anjanesh
Copy link

Is 'html' => view('your-pdf-html') the HTML source of the file to be converted to PDF ?

@driesvints
Copy link
Author

@anjanesh yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment