Install NextPDF for CodeIgniter 4
At a glance
Section titled “At a glance”Install the package with Composer. CodeIgniter 4 finds the Services class and helper functions automatically, so you do not register them by hand.
Requirements
Section titled “Requirements”The package composer.json file is the authoritative source for these
constraints. This table restates them for quick reference.
| Dependency | Constraint | Notes |
|---|---|---|
| PHP | >=8.4 <9.0 | Targets PHP 8.4. |
nextpdf/core | ^3.0 || ^5.2 | The NextPDF engine. |
codeigniter4/framework | ^4.6 | Verified with CodeIgniter 4.7.0. |
ext-mbstring | required at runtime | Validated once per process. |
ext-zlib | required at runtime | Validated once per process. |
Optional packages declared under suggest add these features:
| Package | Adds |
|---|---|
nextpdf/artisan | Chrome DevTools Protocol (CDP) HTML renderer, auto-detected at document build. |
nextpdf/premium | NextPDF Pro and Enterprise features: signing, PDF/A, Factur-X. |
codeigniter4/queue | Asynchronous PDF generation with GeneratePdfJob. |
Install
Section titled “Install”Install the package with Composer:
composer require nextpdf/codeigniterComposer resolves nextpdf/core and codeigniter4/framework against
the constraints above. You do not need to edit a service provider,
bundle, or a bootstrap file.
How discovery works
Section titled “How discovery works”CodeIgniter 4 scans Composer packages for framework elements when
Config\Modules::$discoverInComposer is true, the framework default.
The package includes a NextPDF\CodeIgniter\Config\Services class. That
class lives in the PHP Standard Recommendation 4 (PSR-4) namespace
NextPDF\CodeIgniter\, which maps to src/CodeIgniter/. Composer’s
PSR-4 autoloader converts the fully qualified class name into a file
path. The top-level namespace is required (PSR-4 §x1.x2.p5, modal MUST).
The namespace prefix maps to the base directory, so the class resolves
to its file (PSR-4 §x1.x3).
The package’s Composer files autoload entry
(src/CodeIgniter/Helpers/pdf_helper.php) registers the two helper
functions pdf() and pdf_document(). The package Registrar also
advertises the pdf helper to CodeIgniter’s helper loader. See
/integrations/codeigniter/boot-and-discovery/ for the full sequence.
Verify the install
Section titled “Verify the install”Confirm that Composer resolved the package:
composer show nextpdf/codeigniterConfirm that CodeIgniter discovered the Services class. In any controller,
or in a short php spark route, call the service and assert its type:
<?php
declare(strict_types=1);
use NextPDF\CodeIgniter\Config\Services;use NextPDF\Core\Document;
$document = Services::pdfDocument(false);
// $document is a fresh NextPDF\Core\Document instance.\assert($document instanceof Document);If Services::pdfDocument() returns a Document, discovery works. If
it returns null, discovery did not run. See
/integrations/codeigniter/troubleshooting/.
Edge cases & gotchas
Section titled “Edge cases & gotchas”- If the host application sets
Config\Modules::$discoverInComposertofalse, addnextpdf/codeigniterto the$composerPackages['only']list. Otherwise, CodeIgniter skips the package. - A stale Composer autoloader can hide the Services class. Run
composer dump-autoloadafter you upgrade. - The package declares
codeigniter4/queueonly as a development dependency. A production application that dispatchesGeneratePdfJobmust requirecodeigniter4/queuedirectly.
Security notes
Section titled “Security notes”Install from Packagist over HTTPS. Pin resolved versions in
composer.lock. The package adds no install-time scripts. See
/integrations/codeigniter/security-and-operations/.
Conformance
Section titled “Conformance”- Composer discovery depends on PSR-4 autoloading.
See also
Section titled “See also”- /integrations/codeigniter/overview/ — package capabilities.
- /integrations/codeigniter/quickstart/ — create your first PDF in a controller.
- /integrations/codeigniter/configuration/ — configuration keys and overrides.
- /integrations/codeigniter/boot-and-discovery/ — detailed discovery sequence.