Skip to content

NextPDF CodeIgniter integration

Install the package, and CodeIgniter 4 wires it in for you. Use this page to confirm the wiring: discovery, the bindings model, configuration publishing, and a one-method smoke test that proves the integration works.

Terminal window
composer require nextpdf/codeigniter

You do not need to edit a service provider or change a bootstrap file. See /integrations/codeigniter/install/ for the verified version constraints.

CodeIgniter 4 finds the package through Composer package discovery when Config\Modules::$discoverInComposer is true, the framework default. The PHP Standard Recommendation 4 (PSR-4) prefix NextPDF\CodeIgniter\ maps to src/CodeIgniter/, so the framework can resolve NextPDF\CodeIgniter\Config\Services to its file (PSR-4 §x1.x3). /integrations/codeigniter/boot-and-discovery/ documents the full sequence and the governing Config\Modules properties.

CodeIgniter 4 does not ship a PSR-11 container. PSR-11 §1.3 discourages the service-locator pattern (modal SHOULD NOT). The package follows the framework’s locator convention and keeps it minimal. Each binding is a named static factory with a bool $getShared parameter.

Service nameReturnsDefault lifetime
fontRegistryFontRegistryInterfaceshared
imageRegistryImageRegistryshared
documentFactoryDocumentFactoryInterfaceshared
pdfDocumentDocumentfresh
pdfPdffresh
tsaClient?TsaClientshared
pdfSigner?SignerInterfacefresh

Use either entry point; they are equivalent:

<?php
declare(strict_types=1);
use NextPDF\CodeIgniter\Config\Services;
$a = Services::pdf(false); // direct
$b = \service('pdf'); // helper → Services::pdf()

The pdf() and pdf_document() global helpers wrap Services::pdf(false) and Services::pdfDocument(false).

The package configuration lives in NextPDF\CodeIgniter\Config\NextPdf, a non-final BaseConfig. You can override it in either of two supported ways:

1. Extend the class (typed, version-controlled). Create app/Config/NextPdf.php:

<?php
declare(strict_types=1);
namespace Config;
use NextPDF\CodeIgniter\Config\NextPdf as BaseNextPdf;
final class NextPdf extends BaseNextPdf
{
public int $imageCacheMb = 100;
}

CodeIgniter loads your application class instead of the package default.

2. Override with .env (per-environment). Use the lowercase short class name, nextpdf, as the prefix:

nextpdf.imageCacheMb = 100
nextpdf.signature.enabled = true
nextpdf.signature.certificate = /etc/nextpdf/cert.pem

/integrations/codeigniter/configuration/ documents each key and the array-override rule.

CodeIgniter has no service provider or bundle class to test. Use the equivalent smoke test to check two things: discovery resolved the services, and lifetimes behave as specified. The controller action below is runnable and mirrors the package’s own functional assertions.

<?php
declare(strict_types=1);
namespace App\Controllers;
use CodeIgniter\HTTP\ResponseInterface;
use NextPDF\CodeIgniter\Config\Services;
use NextPDF\CodeIgniter\Libraries\Pdf;
use NextPDF\Core\Document;
final class NextPdfSmokeController extends BaseController
{
public function check(): ResponseInterface
{
// Discovery resolved the services.
$document = Services::pdfDocument(false);
$library = Services::pdf(false);
// Documents are fresh per call (no cross-request leakage).
$freshIsolated = Services::pdfDocument(false) !== $document;
// Registries are shared singletons.
$registrySingleton = Services::fontRegistry() === Services::fontRegistry();
// Optional services degrade to null without Premium / TSA config.
$signerOptional = Services::pdfSigner(false) === null;
$ok = $document instanceof Document
&& $library instanceof Pdf
&& $freshIsolated
&& $registrySingleton
&& $signerOptional;
return $this->response
->setStatusCode($ok ? 200 : 500)
->setJSON([
'discovery' => $document instanceof Document,
'document_fresh_per_call' => $freshIsolated,
'registry_shared' => $registrySingleton,
'signer_optional_null' => $signerOptional,
]);
}
}

Map a route to this action, then request it. A 200 response with all flags set to true proves the integration. Each assertion here matches a behavior verified in the package’s functional test suite.

  • If the host application turns off Composer discovery, add nextpdf/codeigniter to Config\Modules::$composerPackages['only'].
  • Services::pdfDocument(true) returns a shared document. It exists for test reset only. Never request the shared document in request or job code.
  • Services::pdfSigner() and Services::tsaClient() return null until signing or a Time-Stamping Authority (TSA) endpoint is configured. This is intended graceful degradation, not a failure.
  • Class-path mapping for module discovery (PSR-4 Autoloader §x1.x3).
  • Service-locator guidance for the bindings model (PSR-11 Container §1.3).

NextPDF core is Apache-2.0. After you install Pro or Enterprise, its services appear on the same Services surface. The CodeIgniter package exposes the matching service methods. Each method returns null until you install the matching Premium package. See </get-license/?intent=codeigniter>.

  • /integrations/codeigniter/boot-and-discovery/ — discovery internals.
  • /integrations/codeigniter/install/ — version constraints and verification.
  • /integrations/codeigniter/quickstart/ — first PDF.
  • /integrations/codeigniter/production-usage/ — controllers wired through dependency injection and the queue job.
  • /integrations/codeigniter/configuration/ — every configuration key.