Skip to content

TCPDF compatibility developer guide

The compatibility adapter is a migration layer. It makes legacy behavior visible instead of hiding it. Use it to keep your application running while you move high-value paths to native NextPDF APIs.

Use this guide when you maintain legacy TCPDF-shaped code, add adapter coverage, or plan a staged migration to native NextPDF APIs.

LayerOwned byResponsibilityDo not put here
Legacy applicationApplicationKeep existing TCPDF-shaped calls running during migration.New PDF features that should use native NextPDF APIs.
Adapter shellnextpdf/compat-legacyExpose the TCPDF-shaped class and shared compatibility state.Large method families or conversion logic.
Concern traitsnextpdf/compat-legacyGroup legacy method families: text, fonts, images, security, forms, pages.Cross-family output policy.
Bridge classesnextpdf/compat-legacyConvert legacy arguments, destinations, colors, units, and formats.Business-specific behavior.
Core enginenextpdf/nextpdfCreate the native document.Legacy compatibility promises.
StageBehaviorDeveloper action
BootstrapAn optional legacy bootstrap exposes compatibility names.Use it only where legacy code expects TCPDF symbols.
ConstructionThe adapter maps legacy constructor arguments to the core document config.Keep constructor inputs stable during migration.
Method callSupported methods map to NextPDF behavior through concerns and bridges.Check method coverage before you assume parity.
Unsupported featureThe adapter throws explicit compatibility exceptions for unsupported behavior.Replace the call or isolate it behind application code.
OutputThe output bridge maps legacy destination behavior to NextPDF output.Validate filenames and storage roots.

Start by collecting every TCPDF method call in your application. Classify each call before you change behavior.

ClassificationMeaningAction
Supported adapter methodThe method is documented as supported and has tests.Keep it temporarily, then migrate when you touch the area.
Partial adapter methodThe method exists, but behavior does not fully match legacy TCPDF.Add fixture tests and validate output manually.
Explicit unsupported methodThe adapter throws a compatibility exception.Replace it with native NextPDF or remove the feature.
Business-specific wrapperThe application already wraps TCPDF calls.Migrate the wrapper internals first.
Compliance-sensitive callSignature, encryption, tagging, PDF/A, accessibility, or invoice flow.Migrate to native NextPDF APIs with dedicated verification.

Add compatibility support in the smallest method family that owns that behavior.

Change typeWhere to implementRequired test
Text output methodConcerns\AdaptsTextOutput or the font concern.Legacy fixture plus native output assertion.
Page or margin methodPage, positioning, or margin concern.Coordinate conversion and page state test.
Image or drawing methodImage, drawing, color, or gradient concern.Input validation and visual/structural output test.
Output destinationOutputBridge.Destination mapping and unsafe path test.
Unsupported featureException factory or method coverage table.Exception type and message test.

Do not put a large method directly in the adapter shell when a concern trait owns the family.

Use the adapter to stabilize legacy code, then move stable workflows to native APIs.

<?php
// Temporary compatibility code.
$pdf = new \NextPDF\Compat\Tcpdf\TCPDF();
$pdf->AddPage();
$pdf->SetFont('dejavusans', '', 12);
$pdf->Cell(0, 10, 'Invoice 1234');
// Target native shape.
$document = \NextPDF\Core\Document::createStandalone();
$document->addPage()
->setFont('dejavusans', '', 12)
->cell(0, 10, 'Invoice 1234');

Treat migration as a sequence of small behavioral moves. A page can still use the adapter while one high-risk section moves to native APIs.

Extension pointUse it forConstraint
AdaptationConfigControl adapter behavior during migration.Keep defaults explicit and reviewed.
Concern traitsGroup method families such as text, forms, images, or security.Add methods to the appropriate concern, not the adapter shell.
Bridge classesConvert legacy argument shapes into core values.Cover bridge behavior with migration tests.
CompatAdapterInterfaceAdapter-level abstraction for tooling.Do not use as a replacement for native core contracts in new code.
Method coverage tableDeveloper-facing support record.Update it when support status changes.
  1. Install the adapter and run the legacy test suite unchanged.
  2. Open method coverage and classify every called method.
  3. Replace unsupported methods first.
  4. Move high-volume or compliance-sensitive paths to native core APIs.
  5. Add fixture coverage for every migrated method family.
  6. Remove bootstrap aliases when no application entrypoint depends on them.
FailureWhere it should be handledRecommended response
Unsupported methodAdapter exception.Replace the call or isolate it behind an application adapter.
Partial layout parityMigration tests and visual review.Document the accepted difference before rollout.
Unsafe output destinationOutputBridge and application storage policy.Reject unsafe paths and prefer native output APIs.
Security feature mismatchNative migration plan.Do not ship compatibility-only behavior for regulated outputs.
Bootstrap alias collisionApplication bootstrap.Remove global aliases or scope them to legacy entrypoints.
ConcernDefaultWhen to override
Unsupported methodsThrow explicit exception.Do not weaken this in production.
Legacy defaultsCentralized in LegacyDefaults.Override only for known migration behavior.
Output mappingGoes through OutputBridge.Use native output APIs after migration.
Coverage sourceMethod coverage page and tests.Run coverage checks again after each adapter upgrade.
Strict modeKeep enabled during migration audits.Disable only for a documented legacy compatibility window.
  • Keep a legacy fixture for each migrated method family.
  • Add one native NextPDF test before you replace a legacy method.
  • Assert that unsupported methods throw the documented exception.
  • Compare output structure when exact byte equality is not a realistic migration target.
  • Run method coverage checks after you add or change adapter methods.
  • Add storage path tests for every output destination that legacy code uses.