Skip to content

Install NextPDF for CodeIgniter 4

Install the package with Composer. CodeIgniter 4 finds the Services class and helper functions automatically, so you do not register them by hand.

The package composer.json file is the authoritative source for these constraints. This table restates them for quick reference.

DependencyConstraintNotes
PHP>=8.4 <9.0Targets PHP 8.4.
nextpdf/core^3.0 || ^5.2The NextPDF engine.
codeigniter4/framework^4.6Verified with CodeIgniter 4.7.0.
ext-mbstringrequired at runtimeValidated once per process.
ext-zlibrequired at runtimeValidated once per process.

Optional packages declared under suggest add these features:

PackageAdds
nextpdf/artisanChrome DevTools Protocol (CDP) HTML renderer, auto-detected at document build.
nextpdf/premiumNextPDF Pro and Enterprise features: signing, PDF/A, Factur-X.
codeigniter4/queueAsynchronous PDF generation with GeneratePdfJob.

Install the package with Composer:

Terminal window
composer require nextpdf/codeigniter

Composer resolves nextpdf/core and codeigniter4/framework against the constraints above. You do not need to edit a service provider, bundle, or a bootstrap file.

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.

Confirm that Composer resolved the package:

Terminal window
composer show nextpdf/codeigniter

Confirm 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/.

  • If the host application sets Config\Modules::$discoverInComposer to false, add nextpdf/codeigniter to the $composerPackages['only'] list. Otherwise, CodeIgniter skips the package.
  • A stale Composer autoloader can hide the Services class. Run composer dump-autoload after you upgrade.
  • The package declares codeigniter4/queue only as a development dependency. A production application that dispatches GeneratePdfJob must require codeigniter4/queue directly.

Install from Packagist over HTTPS. Pin resolved versions in composer.lock. The package adds no install-time scripts. See /integrations/codeigniter/security-and-operations/.

  • Composer discovery depends on PSR-4 autoloading.
  • /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.