Forked from driesvints/gist:70162727698210274c3982ad87b37ed5
Created
January 28, 2026 08:18
-
-
Save niladam/50f325365b939de282e87a6a4426977f to your computer and use it in GitHub Desktop.
Cloudflare PDF generation in Laravel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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