Package Laravel
Laravel · LGPL-3.0Le package Laravel (yeeefang/tcpdf-next-laravel) fournit une intégration Laravel 12 de première classe avec :
- ServiceProvider auto-découvert — bindings DI, services scopés sûrs pour Octane
- Facade
Pdf— accès statique pratique PdfResponse— helpers de réponse HTTP sécurisés (inline/download)GeneratePdfJob— génération PDF async basée sur file d'attente
Installation
bash
composer require yeeefang/tcpdf-next-laravelPrérequis : Laravel ^12.0
Le ServiceProvider est auto-découvert. Publiez la config :
bash
php artisan vendor:publish --tag=tcpdf-next-configDémarrage rapide
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");
}
}Bindings du Service Provider
| Interface | Binding | Scope |
|---|---|---|
PdfDocumentInterface | Document::create() | Factory (nouveau par résolution) |
FontManagerInterface | FontManager | Scoped (frais par requête, sûr pour Octane) |
SignerInterface | Configuré depuis config/tcpdf-next.php | Factory |
Le TcpdfServiceProvider fusionne des valeurs par défaut sensées depuis le fichier de config fourni et enregistre tous les bindings avant le démarrage de votre application. Dans les environnements Laravel Octane, les bindings scopés sont automatiquement vidés entre les requêtes pour éviter les fuites d'état.
Structure du package
Yeeefang\TcpdfNext\Laravel\
├── TcpdfServiceProvider # Bindings DI, publication config
├── Facades\
│ └── Pdf # Proxy statique vers factory Document
├── Http\
│ └── PdfResponse # Helpers réponse inline / download
└── Jobs\
└── GeneratePdfJob # Génération PDF async queueableInjection de dépendance
Au lieu de la Facade, injectez directement le contrat :
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();
}
}Prochaines étapes
- Facade Pdf — Accès statique et helpers de test
- Réponses HTTP — Affichage inline et téléchargements sécurisés
- Jobs de file d'attente — Génération PDF async avec callbacks
- Configuration — Référence de config complète
