Forked from driesvints/gist:70162727698210274c3982ad87b37ed5
Created
January 27, 2026 13:14
-
-
Save daleweaver777/5371ebc733c8b08f5187b1e92d13b430 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