Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save daleweaver777/5371ebc733c8b08f5187b1e92d13b430 to your computer and use it in GitHub Desktop.

Select an option

Save daleweaver777/5371ebc733c8b08f5187b1e92d13b430 to your computer and use it in GitHub Desktop.
Cloudflare PDF generation in Laravel.
// Controller method...
public function download()
{
return response()->streamDownload(function () use ($invoice) {
$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'),
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment