setasign/fpdi
FPDI is a PHP library that lets you import pages from existing PDF documents and use them as templates in FPDF, TCPDF, or tFPDF. It requires no special PHP extensions, supports PSR-4 autoloading, and offers fast performance with low memory use.
PdfService facade) or queue-based workflows (e.g., generating PDFs asynchronously). Can be wrapped in a service provider for dependency injection./generate-invoice) or command-line tasks (e.g., Laravel Artisan commands) for batch processing.Storage facade).PdfService interfaces).try-catch blocks around FPDI operations). v2.6.9 adds handling for escaped dictionary keys, which improves resilience against non-standard/hostile PDF structures — a small but real reduction in parser-level risk for customer-supplied template uploads.Output('S') in FPDF) to reduce memory spikes.2.3.x). v2.6.9 explicitly verifies compatibility with PHP 8.6, so the 2.6.x line remains a safe pin for teams tracking PHP 8.2–8.6 upgrades.composer.json strict versioning or platform checks (e.g., if (class_exists('FPDF'))) to avoid conflicts.set_time_limit() or Laravel’s queue:work --timeout).dompdf) or augment it (e.g., for template inheritance)?Log facade or Sentry).dompdf if template fidelity is critical.Storage facade to handle PDF sources (e.g., storage_path('app/templates/invoice.pdf')).GeneratePdfJob) for long-running tasks.POST /pdfs/invoice) with auth (e.g., Sanctum, Passport).InvoicePdfService).config('pdf.use_fpdi')) to toggle between old/new logic.^2.6) to avoid breaking changes; v2.6.9 is the current recommended patch within that constraint.composer require setasign/fpdi:^2.6 --dev).tecnickcom/tcpdf:6.11.*.setasign/fpdf:1.9.*.setasign/tfpdf:1.33.*.2.3.x.php:8.2-fpm (or php:8.6-fpm where validated) with composer install in Dockerfile.composer require setasign/fpdi:^2.6 tecnickcom/tcpdf
composer.json:
"autoload": {
"psr-4": {
"App\\Services\\": "app/Services/",
"setasign\\Fpdi\\": "vendor/setasign/fpdi/src/"
}
}
PdfService facade:
namespace App\Services;
use setasign\Fpdi\Tcpdf\Fpdi;
class PdfService {
public function generateInvoice($templatePath, $data) {
$pdf = new Fpdi('P', 'mm', 'A4');
$pdf->setSourceFile($templatePath);
$tplId = $pdf->importPage(1);
$pdf->useTemplate($tplId, 10, 10, 100);
// Add dynamic content...
return $pdf->Output('invoice.pdf', 'S');
}
}
composer update setasign/fpdi --with-dependencies, execute the PDF regression fixture suite, and deploy — no code changes expected.Log/Sentry, and add queue timeouts for untrusted template sources.^2.6 in composer.json and rely on CI to catch transitive FPDF/TCPDF conflicts.Output('S')), and cap concurrency per worker pool.queue:work --timeout and memory_limit per worker; alert on repeated job failures.setSourceFile, importPage, useTemplate) is learnable in under a day for a PHP developer familiar with Laravel.How can I help you explore Laravel packages today?