Skip to content

Add TcLibPdf engine (tc-lib-pdf), deprecate Tcpdf engine - #339

Merged
ADmad merged 5 commits into
masterfrom
feature/tc-lib-pdf-engine
Jun 19, 2026
Merged

ADmad merged 5 commits into
masterfrom
feature/tc-lib-pdf-engine

Conversation

@dereuromark

@dereuromark dereuromark commented Jun 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds a new TcLibPdfEngine backed by the actively maintained
tecnickcom/tc-lib-pdf library, the
successor of the now upstream-deprecated tecnickcom/tcpdf package. The
existing TcpdfEngine is marked @deprecated and points to the new engine.

Why

tecnickcom/tcpdf is flagged as deprecated on Packagist ("Deprecated legacy PDF
engine for PHP"). tc-lib-pdf is the maintained rewrite from the same author and
keeps HTML to PDF support via addHTMLCell().

What it does

  • Renders the CakePdf HTML through tc-lib-pdf's addHTMLCell() (which flows long
    content across pages automatically).
  • Maps orientation and pageSize from the CakePdf instance.
  • Honors the standard CakePdf margin setting, with an engine-specific
    options.margins fallback per side.
  • Exposes unit, unicode, subsetFont, compress, mode (PDF/A, PDF/X,
    PDF/UA conformance), font and metadata under the documented options
    config key.
  • Marks TcpdfEngine deprecated.

Fonts requirement

Unlike tcpdf, tc-lib-pdf ships no fonts. Consumers must provide the standard PDF
core fonts as generated *.json files via the K_PATH_FONTS constant. This is
documented in the README. The engine test bundles the core-14 font definitions
under tests/fonts/ so CI can render real PDFs.

Note

The bundled font metric data was generated from the URW base35 fonts
(fonts-urw-base35, AGPLv3 with font exception), which are metric-compatible
with the standard PDF core fonts. The core 14 are referenced by name and not
embedded, so these files carry only metrics and encoding tables, no glyph
outlines. See tests/fonts/README.md. Happy to swap the fixtures for fonts
generated via tecnickcom's own tooling if preferred for licensing clarity.

Notes

  • tecnickcom/tc-lib-pdf: ^8 added to require-dev and suggest.
rendered-pdf-page

Add a new TcLibPdfEngine backed by the actively maintained
tecnickcom/tc-lib-pdf library, the successor of the now upstream-deprecated
tecnickcom/tcpdf package. The existing TcpdfEngine is marked deprecated and
points users to the new engine.

The engine renders the CakePdf HTML via tc-lib-pdf's addHTMLCell(), maps
orientation and page size from the CakePdf instance, honors the standard
CakePdf margin setting (with an engine-specific margins fallback), and exposes
unit, unicode, font, metadata and conformance mode options under the documented
options config key.

Unlike tcpdf, tc-lib-pdf ships no fonts, so the standard PDF core fonts must be
provided as generated JSON files via the K_PATH_FONTS constant. This is
documented in the README. The core-14 font definitions used by the engine test
are bundled under tests/fonts (metric data generated from the URW base35 fonts;
see tests/fonts/README.md for provenance).
Cast CakePdf::margin() (typed static|array) to array before array access so
psalm no longer reports an undefined offsetGet on the static branch.

Raise the tecnickcom/tc-lib-pdf constraint to ^8.5: the HTML rendering API
(addHTMLCell) the engine relies on was introduced in 8.5.0, so the previous ^8
floor failed on the prefer-lowest build.
The lowest tc-lib-pdf-font release (2.6.4) types Stack::insert() $size as ?int,
while newer releases accept float. Cast to int so the prefer-lowest build works
across the whole supported range.
Comment thread src/Pdf/Engine/TcLibPdfEngine.php Resolved
Comment thread src/Pdf/Engine/TcpdfEngine.php Resolved
@ADmad
ADmad merged commit 9c478eb into master Jun 19, 2026
8 checks passed
@ADmad
ADmad deleted the feature/tc-lib-pdf-engine branch June 19, 2026 18:25
@dereuromark

Copy link
Copy Markdown
Member Author

It actually wasnt too difficult to set the font and replace the deprecated one:
dereuromark/cakephp-sandbox#141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants