5 min read · Beginner friendly
Quickstart
Generate your first PDF from a Laravel Blade view. You will install the package, add an API key, create a simple view, and return a downloadable PDF from a route.
What you'll do
Install the Laravel package
Render a Blade view into a PDF
Download the PDF from your browser
1. Install the package
Terminal
bash
1composer require bladepdf/laravel
2php artisan vendor:publish --tag=bladepdf-config
2. Add your API key
Create an API key in the dashboard and add it to your environment.
.env
env
1BLADEPDF_API_KEY=blpdf_xxxxxxxxxxxxxxxxxxxxxxxx
3. Create a Blade view
Create resources/views/pdf/invoice.blade.php.
resources/views/pdf/invoice.blade.php
blade
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>
4. Return the PDF
Add a route or controller action that renders the view.
routes/web.php
php
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});
5. Test it
Start your Laravel app and open the route in your browser.
Terminal
bash
1php artisan serve
Visit http://localhost:8000/invoices/1/pdf. The browser should download a PDF generated from your Blade view.
Cloud template version
If the template lives in the dashboard instead of your Laravel app, use fromTemplate() and pass JSON-friendly context data.
Cloud template render
php
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");