Last active
January 29, 2026 18:01
-
-
Save driesvints/70162727698210274c3982ad87b37ed5 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 () { | |
| $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
Is
'html' => view('your-pdf-html')the HTML source of the file to be converted to PDF ?