NextPDF compat-legacy integration
At a glance
Section titled “At a glance”Use nextpdf/compat-legacy to connect an application so existing
TCPDF 6.x code runs on the NextPDF engine. The package is a migration
aid, not a permanent shim — remove it after you adopt the modern
application programming interface (API) (see /integrations/tcpdf-compat/migration/). It is a TCPDF-compatible
alternative, not a drop-in clone: 94 of the ~120 surveyed TCPDF methods
delegate directly. The remaining methods have documented behavioral differences
(see /integrations/tcpdf-compat/method-coverage/).
Install
Section titled “Install”composer require nextpdf/compat-legacy:^3.0This resolves nextpdf/core ^3.0 transitively. For full requirements and a
verification check, see /integrations/tcpdf-compat/install/.
Boot and auto-discovery
Section titled “Boot and auto-discovery”The package does not wire globals during autoload. Requiring it does not
create a global \TCPDF. You choose how call sites resolve the class:
- Preferred (explicit imports). Update
use/requirelines touse NextPDF\Compat\Tcpdf\TCPDF;in each file. This is unambiguous and easy to search. - Opt-in global aliases. Call
LegacyBootstrap::enableAliases()once at boot to register\TCPDFand the four helper classes — only if those names are not already taken. The mechanism, idempotency, and the real-TCPDF conflict rule: /integrations/tcpdf-compat/boot-and-discovery/.
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use NextPDF\Compat\Tcpdf\LegacyBootstrap;
// One call at application bootstrap, before any \TCPDF use.LegacyBootstrap::enableAliases();Container bindings
Section titled “Container bindings”The package does not include a framework service provider or bundle. You own the thin integration layer. Bind a factory that returns a fresh adapter for each document — never a shared singleton, because each instance owns document state (see /integrations/tcpdf-compat/production-usage/ § Concurrency).
<?php
declare(strict_types=1);
use NextPDF\Compat\Tcpdf\TCPDF;use Psr\Container\ContainerInterface;
// Pseudocode for a PSR-11-style container: bind a factory, not a shared instance.$container->set(TCPDF::class, static function (ContainerInterface $c): TCPDF { return new TCPDF('P', 'mm', 'A4');});
// Each resolution is an independent document context.$pdf = $container->get(TCPDF::class);In Symfony, register the factory as a non-shared service. In Laravel,
use bind (not singleton) so each resolution gets a new
instance. The package itself remains framework-agnostic.
Publish config
Section titled “Publish config”There is no publishable framework config file. Configure the adapter through the
legacy K_* / PDF_* constants (define them in your bootstrap before
the first construction) or through the modern immutable
NextPDF\Compat\Tcpdf\Config\AdaptationConfig object. See
/integrations/tcpdf-compat/configuration/.
Service-provider / bundle smoke test
Section titled “Service-provider / bundle smoke test”After wiring, verify that the integration produces a valid Portable Document Format (PDF) file. This mirrors
the surface asserted by tests/Unit/Compat/Tcpdf/TcpdfOutputTest.php:
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use NextPDF\Compat\Tcpdf\TCPDF;
$pdf = new TCPDF('P', 'mm', 'A4');$pdf->AddPage();$pdf->SetFont('helvetica', '', 12);$pdf->Cell(0, 10, 'Integration smoke test');
$bytes = $pdf->Output('smoke.pdf', 'S');
assert(str_starts_with($bytes, '%PDF'), 'Integration smoke test failed');echo "Integration OK\n";In a Hypertext Transfer Protocol (HTTP) or worker context, use Output(..., 'F') or 'S'. Do not
rely on the inline path. For full operational guidance, see
/integrations/tcpdf-compat/production-usage/.
Public API entry points
Section titled “Public API entry points”| Entry point | Purpose |
|---|---|
NextPDF\Compat\Tcpdf\TCPDF | TCPDF-compatible facade. Construct one per document. |
TCPDF::getDocument() | Returns the wrapped NextPDF\Core\Document — the modern API escape hatch. |
TCPDF::setStrictMode(bool) | Migration audit toggle (see /integrations/tcpdf-compat/configuration/). |
NextPDF\Compat\Tcpdf\LegacyBootstrap::enableAliases() | Opt-in global class aliases. |
NextPDF\Compat\Tcpdf\Config\AdaptationConfig | Modern immutable configuration object. |
NextPDF\Compat\Contracts\CompatAdapterInterface | Shared compat contract. |
TCPDF API coverage
Section titled “TCPDF API coverage”The authoritative, test-verified coverage matrix lives in the in-repo file
docs/TCPDF_COVERAGE.md. The reader-facing summary — mirrored,
silent-ignore, unimplemented, and not-applicable methods — is
/integrations/tcpdf-compat/method-coverage/. Do not call it a “drop-in replacement” or “100% compatible”
implementation. Describe it as a TCPDF-compatible
alternative with a known, tested surface and documented behavioral
differences.
See also
Section titled “See also”docs/TCPDF_COVERAGE.md— authoritative coverage source in the repo- /integrations/tcpdf-compat/boot-and-discovery/ — facade exposure and alias behavior
- /integrations/tcpdf-compat/method-coverage/ — per-method behavior and gaps
- /integrations/tcpdf-compat/migration/ — staged migration strategy
- /integrations/tcpdf-compat/production-usage/ — how to run the adapter under load
tests/Unit/Compat/Tcpdf/TcpdfOutputTest.php— output behavior oracle