Framework integration
NextPDF CodeIgniter
Lightweight CodeIgniter 4 integration — services, library, and response helpers.
NextPDF CodeIgniter provides first-class CodeIgniter 4 integration for NextPDF. It includes a Pdf library for controllers, CI4 Services with singleton registries, a PdfResponse helper with OWASP security headers, global helper functions, and automatic detection of installed NextPDF extensions (Artisan, Pro).
How it fits
Built into your workflow
Configure with .env
A typed BaseConfig object exposes NextPDF's settings as real PHP properties, and any of them can be overridden from your .env file using the nextpdf.* prefix. Drop in a key, and the change flows through to the Pdf library with no code edits. Defaults stay strongly typed, so your editor and static analysis still see the right shapes.
One-line helpers
The global pdf() and pdf_document() helper shortcuts collapse setup into a single call from anywhere in your app. pdf() builds and delivers a document in one step, while pdf_document() hands you a fresh Document to compose. Both route through the same Pdf library, so behaviour stays consistent whether you use a helper or the service.
Queue heavy renders
Push a GeneratePdfJob onto the CodeIgniter 4 queue and let a background worker render large documents off the request path. The integration builds on codeigniter4/queue, so dispatched jobs are picked up and processed by your existing worker setup. Your controllers stay fast while the finished PDF is produced asynchronously.
Get started
Install
composer require nextpdf/codeigniterIn code
How it works
Controller with the Pdf library
use NextPDF\CodeIgniter\Config\Services;
public function download(int $id): \CodeIgniter\HTTP\DownloadResponse
{
$pdf = Services::pdf();
$pdf->document()->addPage();
$pdf->document()->cell(0, 10, "Invoice #{$id}");
return $pdf->download("invoice-{$id}.pdf");
}Async generation (CI4 Queue)
use NextPDF\CodeIgniter\Jobs\GeneratePdfJob;
service('queue')->push('pdf', GeneratePdfJob::class, [
'builder' => 'App\PdfBuilders\InvoiceBuilder::build',
'outputPath' => WRITEPATH . 'pdfs/invoice-42.pdf',
'context' => ['invoice_id' => 42],
]);Capabilities
What you get
- Pdf library — high-level controller API: build and deliver PDFs in a single call
- CI4 Services — singleton FontRegistry/ImageRegistry, fresh Document per request (worker-safe)
- PdfResponse — inline preview and download responses with OWASP security headers
- Queue support — async generation via GeneratePdfJob and codeigniter4/queue
- Extension detection — auto-discovers Artisan and Pro at boot
- BaseConfig — typed config properties with .env override using the nextpdf.* prefix
- Helper functions — global pdf() and pdf_document() shortcuts for rapid prototyping
When to use it
Choose this for CodeIgniter 4 projects that want a lightweight Pdf library and Services-based registries, with .env-driven configuration and optional CI4 Queue for async jobs.