laravel-pdf maintained by snapapi
Description
SnapAPI driver for spatie/laravel-pdf — generate PDFs via the SnapAPI cloud API, no Chrome to manage
Author
Last update
2026/02/25 14:07
(dev-main)
License
Downloads
0
Tags
SnapAPI Driver for Laravel PDF
A spatie/laravel-pdf v2 driver that generates PDFs via SnapAPI — a managed screenshot and PDF API powered by Chromium. No Chrome to install, no Lambda setup, no Docker layer headaches.
Pdf::view('invoices.receipt', ['invoice' => $invoice])
->format('A4')
->driver(SnapApiDriver::class)
->save(storage_path('invoices/receipt.pdf'));
Why use this?
- ✅ No Chromium to manage — no binary updates, no memory limits to tune
- ✅ Works everywhere — local, shared hosting, serverless, Docker
- ✅ Full CSS support — Flexbox, Grid, Tailwind, web fonts, all rendered by a real Chromium
- ✅ Free tier — 200 PDFs/month, no credit card
Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
- spatie/laravel-pdf v2
- A free SnapAPI key
Installation
composer require snapapi/laravel-pdf
Publish the config file:
php artisan vendor:publish --tag=snapapi-pdf-config
Configuration
Add your API key to .env:
SNAPAPI_KEY=sk_live_your_key_here
Get a free key at snapapi.pics — free tier includes 200 PDFs/month.
Usage
Basic PDF from Blade view
use Spatie\LaravelPdf\Facades\Pdf;
use SnapApi\LaravelPdf\SnapApiDriver;
Pdf::view('pdfs.invoice', ['invoice' => $invoice])
->driver(SnapApiDriver::class)
->save(storage_path('pdfs/invoice.pdf'));
Respond with PDF download
return Pdf::view('pdfs.invoice', ['invoice' => $invoice])
->driver(SnapApiDriver::class)
->format('A4')
->download('invoice.pdf');
Respond inline (open in browser)
return Pdf::view('pdfs.report', $data)
->driver(SnapApiDriver::class)
->inline('report.pdf');
Set format and margins
Pdf::view('pdfs.letter', $data)
->driver(SnapApiDriver::class)
->format('Letter')
->margins(top: 15, right: 10, bottom: 15, left: 10)
->landscape()
->save('/path/to/output.pdf');
From raw HTML
Pdf::html('<h1>Hello World</h1><p>Generated by SnapAPI.</p>')
->driver(SnapApiDriver::class)
->save('/path/to/output.pdf');
Set as default driver
In config/pdf.php (published from spatie/laravel-pdf):
'default_driver' => \SnapApi\LaravelPdf\SnapApiDriver::class,
Then you can omit ->driver() entirely:
Pdf::view('pdfs.invoice', $data)->save('invoice.pdf');
Configuration reference
config/snapapi-pdf.php:
return [
'api_key' => env('SNAPAPI_KEY', ''),
'base_url' => env('SNAPAPI_BASE_URL', 'https://api.snapapi.pics'),
'timeout' => env('SNAPAPI_TIMEOUT', 60),
];
| Key | Default | Description |
|---|---|---|
| api_key | — | Your SnapAPI key (required) |
| base_url | https://api.snapapi.pics | API base URL |
| timeout | 60 | HTTP timeout in seconds |
Testing
composer test
Changelog
1.0.0
- Initial release
- Supports
generatePdfandsavePdf(full spatie/laravel-pdf v2 driver interface) - Paper format, margins, orientation, custom width/height
- Header and footer HTML support
License
MIT — see LICENSE