Skip to content

Laravel Paket

The Laravel package (yeeefang/tcpdf-next-laravel) provides first-class Laravel 12 integration with:

  • Auto-discovered ServiceProvider — DI bindings, Octane-safe scoped services
  • Pdf Facade — convenient static access
  • PdfResponse — secure HTTP response helpers (inline/download)
  • GeneratePdfJob — queue-based async PDF generation

Installationation

bash
composer require yeeefang/tcpdf-next-laravel

Anforderungen: Laravel ^12.0

The ServiceProvider is auto-discovered. Publish the config:

bash
php artisan vendor:publish --tag=tcpdf-next-config

Quick 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

InterfaceBindingScope
PdfDocumentInterfaceDocument::create()Factory (new per resolution)
FontManagerInterfaceFontManagerScoped (fresh per request, Octane-safe)
SignerInterfaceConfigured from config/tcpdf-next.phpFactory

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.

Paket 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 generation

Dependency 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();
    }
}

Nächste Schritte

Veröffentlicht unter der LGPL-3.0-or-later Lizenz.