Quickstart
Generate your first PDF from a copy-paste Laravel route, then see how to adapt it to a real Blade view backed by your application data.
1. Install the package
1composer require bladepdf/laravel
2. Add your API key
Create an API key in the dashboard and add it to your environment.
1BLADEPDF_API_KEY=blpdf_xxxxxxxxxxxxxxxxxxxxxxxx
Configuration is auto-discovered. Publish the config only when you need custom timeouts, retries, SSL settings, or asset resolution. See Configuration for the publish command and available options.
3. First PDF — copy and paste
Add this route to routes/web.php. It uses inline HTML, so it does not need a model, database record, or Blade view.
1use BladePDF\Laravel\Facades\BladePDF;
2
3Route::get('/bladepdf-test', function () {
4 return BladePDF::fromHtml('
5 <h1>Hello from BladePDF</h1>
6 <p>Your first PDF is working.</p>
7 ')
8 ->render()
9 ->download('bladepdf-test.pdf');
10});
Run it
Start your Laravel app and open the test route in your browser.
1php artisan serve
Visit http://localhost:8000/bladepdf-test. The browser should download bladepdf-test.pdf.
Real Blade view example
The following example shows a typical invoice integration. It assumes your application already has an Invoice model with a customer relation and an items collection.
Create the invoice view
Create resources/views/pdf/invoice.blade.php.
1<!doctype html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <style>
6 body { font-family: sans-serif; padding: 40px; color: #111827; }
7 h1 { color: #ff2d20; }
8 table { width: 100%; border-collapse: collapse; margin-top: 32px; }
9 th, td { text-align: left; padding: 8px; border-bottom: 1px solid #e5e7eb; }
10 .total { font-size: 24px; font-weight: 700; margin-top: 24px; }
11 </style>
12</head>
13<body>
14 <h1>Invoice {{ $invoice->number }}</h1>
15 <p>Billed to: {{ $invoice->customer->name }}</p>
16
17 <table>
18 <thead>
19 <tr>
20 <th>Description</th>
21 <th>Amount</th>
22 </tr>
23 </thead>
24 <tbody>
25 @foreach ($invoice->items as $item)
26 <tr>
27 <td>{{ $item->description }}</td>
28 <td>{{ $item->amount }}</td>
29 </tr>
30 @endforeach
31 </tbody>
32 </table>
33
34 <p class="total">Total: {{ $invoice->total }}</p>
35</body>
36</html>
Render the invoice
Add a route or controller action that renders the view using your existing invoice data.
1use App\Models\Invoice;
2use BladePDF\Laravel\Facades\BladePDF;
3use Illuminate\Support\Facades\Route;
4
5Route::get('/invoices/{invoice}/pdf', function (Invoice $invoice) {
6 return BladePDF::fromView('pdf.invoice', [
7 'invoice' => $invoice,
8 ])
9 ->templateName('Invoice')
10 ->reference($invoice->uuid)
11 ->format('A4')
12 ->showBackground()
13 ->render()
14 ->download("invoice-{$invoice->number}.pdf");
15});
Cloud template version
If the template lives in the dashboard instead of your Laravel app, use fromTemplate() and pass JSON-friendly context data.
1return BladePDF::fromTemplate('invoice.standard', [
2 'invoice' => $invoice->toArray(),
3 'customer' => $invoice->customer->toArray(),
4])
5 ->reference($invoice->uuid)
6 ->storePdf()
7 ->render()
8 ->download("invoice-{$invoice->number}.pdf");