Laravel Package
Laravel · LGPL-3.0The Laravel package (yeeefang/tcpdf-nextlaravel) provides first-class Laravel 12 integration with:
- Auto-discovered ServiceProvider — DI bindings, Octane-safe scoped services
PdfFacade — convenient static accessPdfResponse— secure HTTP response helpers (inline/download)GeneratePdfJob— queue-based async PDF generation
Installation
bash
composer require yeeefang/tcpdf-nextlaravelRequirements: Laravel ^12.0
The ServiceProvider is auto-discovered. Publish the config:
bash
php artisan vendor:publish --tag=tcpdf-next-configQuick Start
php
use Yeeefang\TcpdfNext\Laravel\Facades\Pdf;
use Yeeefang\TcpdfNext\Laravel\Http\PdfResponse;
class InvoiceController extends Controller
{
public function download(Invoice $invoice)
{
$pdf = Pdf::create()
->setTitle("Invoice #{$invoice->number}")
->addPage()
->setFont('DejaVuSans', '', 12)
->cell(0, 10, "Invoice #{$invoice->number}");
return PdfResponse::download($pdf, "invoice-{$invoice->number}.pdf");
}
}Service Provider Bindings
| Interface | Binding | Scope |
|---|---|---|
PdfDocumentInterface | Document::create() | Factory (new per resolution) |
FontManagerInterface | FontManager | Scoped (fresh per request, Octane-safe) |
SignerInterface | Configured from config/tcpdf-next.php | Factory |
The TcpdfServiceProvider merges sensible defaults from the shipped config file and registers all bindings before your application boots. In Laravel Octane environments, scoped bindings are automatically flushed between requests to prevent state leakage.
Package Structure
Yeeefang\TcpdfNext\Laravel\
├── TcpdfServiceProvider # DI bindings, config publishing
├── Facades\
│ └── Pdf # Static proxy to Document factory
├── Http\
│ └── PdfResponse # Inline / download response helpers
└── Jobs\
└── GeneratePdfJob # Queueable async PDF generationDependency Injection
Instead of the Facade, inject the contract directly:
php
use Yeeefang\TcpdfNext\Contracts\PdfDocumentInterface;
class ReportService
{
public function __construct(
private readonly PdfDocumentInterface $pdf,
) {}
public function generate(array $data): string
{
return $this->pdf
->addPage()
->setFont('Helvetica', 'B', 16)
->cell(0, 10, 'Monthly Report')
->setFont('Helvetica', '', 12)
->cell(0, 10, "Generated: " . now()->format('F j, Y'))
->output();
}
}Next Steps
- Pdf Facade — Static access and testing helpers
- HTTP Responses — Inline display and secure downloads
- Queue Jobs — Async PDF generation with callbacks
- Configuration — Full config reference