tc-lib-pdf (TCPDF)

Open Source PHP class for generating PDF documents

tc-lib-pdf is the new generation of TCPDF for modern PHP. Generate production PDFs in pure PHP 8.2+ with a modular, Composer-first architecture built for maintainability and long-term evolution.

TCPDF started in 2002 and became one of the most widely adopted PDF engines in the PHP ecosystem. Today, active development continues in tc-lib-pdf and the tc-lib package stack.

IMPORTANT: Maintaining a project for decades that has been installed hundreds of millions of times takes sustained engineering effort, testing, and support. If this project is useful to you, please consider supporting ongoing development via GitHub Sponsors.

Start Here

  • Install:
composer require tecnickcom/tc-lib-pdf

Why tc-lib-pdf

tc-lib-pdf is a deterministic, pure-PHP PDF toolkit with no external rendering service requirements. It modernizes the original TCPDF approach into focused packages, stricter typing, and cleaner integration boundaries.

  • Modern baseline: PHP 8.2+, Composer-first, modular dependencies.
  • Production features: advanced typography, graphics, security, standards, and forms.
  • Predictable output: deterministic generation suitable for invoices, reports, labels, and archival workflows.
  • Flexible adoption: use the full stack or install only the tc-lib packages your project needs.

Legacy TCPDF vs New tc-lib-pdf

The legacy TCPDF repository is deprecated:

Recommendation:

  • Starting a new project: use tc-lib-pdf.
  • Running legacy TCPDF in production: keep it stable short-term and plan phased migration.

Migration matters because tc-lib-pdf is where active evolution continues.

For TCPDF Users

If you already know TCPDF, tc-lib-pdf will feel familiar in purpose but it is not positioned as a drop-in replacement.

  • The codebase is split across focused Composer packages instead of a single monolithic distribution.
  • The API surface is more strongly typed and organized around companion services such as fonts, pages, graphics, and images.
  • Setup is Composer-first, which means asset preparation such as font generation is part of project bootstrap rather than an implicit bundled step.

The fastest way to evaluate the library is to follow the installation and font setup steps below, then compare runnable examples with the equivalent workflows you already maintain in TCPDF.

Requirements

  • PHP 8.2 or later
  • Required PHP extensions: date, pcre (enforced by Composer)
  • Composer

Optional PHP extensions for extended functionality: gd, zlib.

Feature-specific prerequisites:

  • Digital signatures, timestamps, and LTV workflows require signing certificates/keys and any external TSA or revocation endpoints your configuration references.
  • make preflight depends on external validation tools when you want standards validation beyond the built-in sample generation.

Installation

For a clean first run:

  1. Install the package with Composer.
  2. Generate the companion font files.
  3. Run the minimal script using the generated K_PATH_FONTS path.
composer require tecnickcom/tc-lib-pdf

Or add to your composer.json:

{
    "require": {
        "tecnickcom/tc-lib-pdf": "^8"
    }
}

Font Setup

Font generation is required before the bundled and companion fonts can be used. The detailed workflow now lives on /docs/fonts/, including Composer hooks, manual generation, custom font import, and licensing notes.

For the common case, add this hook to your consuming project’s composer.json:

{
    "scripts": {
        "tc-lib-pdf-fonts": [
            "[ -d vendor/tecnickcom/tc-lib-pdf-font ] && make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts || true"
        ],
        "post-install-cmd": [
            "@tc-lib-pdf-fonts"
        ],
        "post-update-cmd": [
            "@tc-lib-pdf-fonts"
        ],
        "post-autoload-dump": [
            "@tc-lib-pdf-fonts"
        ]
    }
}

To build fonts manually from the project root:

make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts

Quick Start

The following example assumes the script lives in your project root. If you place it elsewhere, adjust the autoload.php and K_PATH_FONTS paths accordingly.

<?php

require(__DIR__ . '/vendor/autoload.php');

\define('K_PATH_FONTS', \realpath(__DIR__ . '/vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));

$pdf = new \Com\Tecnick\Pdf\Tcpdf();

$bfont = $pdf->font->insert($pdf->pon, 'helvetica', '', 12);

$page = $pdf->addPage();

$pdf->page->addContent($bfont['out']);

$html = '<h1>Hello, PDF!</h1><p>Generated with tc-lib-pdf.</p>';

$pdf->addHTMLCell(
        html:   $html,
        posx:   15,
        posy:   20,
        width:  180,
);

$rawpdf = $pdf->getOutPDFString();

$pdf->renderPDF($rawpdf);

getOutPDFString() returns the raw PDF bytes. renderPDF() streams those bytes to the browser.

If the minimal example fails on first run, verify these two points first:

  • K_PATH_FONTS resolves to an existing generated font directory.
  • The companion fonts were generated after composer install or composer update.

For more complete examples, see /examples/.

What You Can Build

  • Invoices, receipts, and financial statements
  • Shipping labels and barcode-driven logistics documents
  • Compliance and archival PDFs, including PDF/A workflows
  • Branded reports with custom fonts, SVG, and advanced layout controls
  • Interactive documents with forms, annotations, and signatures

Key Capabilities

  • Typography and fonts: Unicode, RTL, subsetting, custom fonts, and font tooling. See /docs/fonts/.
  • Secure and network-aware integrations: host allowlists and transport controls for remote assets. See /docs/remote-resources/.
  • Signature workflows: detached CMS signatures, TSA timestamps, and LTV material. See /docs/digital-signatures/.
  • Standards modes: PDF/A, PDF/X, and PDF/UA conformance. See /docs/standards/.
  • PDF reuse: import and place pages from existing PDFs. See /docs/pdf-import/.
  • Build and packaging workflow: QA, preflight, RPM, and DEB targets. See /docs/development/.

In-Depth Guides

tc-lib-* Ecosystem

tc-lib-pdf is built on a set of focused, independently versioned packages. Each can be used standalone or as part of the full stack:

Contributing

Contributions are welcome. Please read CONTRIBUTING.md and CODE_OF_CONDUCT.md before submitting a pull request.

  1. Fork the repository and create a feature branch.
  2. Write or update tests for your change.
  3. Run make qa to ensure the full pipeline passes.
  4. Open a pull request with a clear description of the change.

Security vulnerabilities should be reported according to SECURITY.md.

Contact

Nicola Asuni — info@tecnick.com


© 2004-2026 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy
Morty Proxy This is a proxified and sanitized view of the page, visit original site.