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.1+ 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.

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.1+, 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.

Requirements

  • PHP 8.1+
  • Composer
  • Optional extensions: gd, zlib

Installation

composer require tecnickcom/tc-lib-pdf

Or add to your composer.json:

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

Font Setup

When you install tc-lib-pdf as a dependency in your project (via composer require or composer install), the fonts from the companion package tc-lib-pdf-font must be generated before they can be used.

Since Composer does not execute dependency scripts during installation, you need to add the font generation step to your consuming project’s composer.json file:

{
  "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"
    ]
  }
}

This ensures fonts are generated automatically when you run:

composer install
composer update
composer require ...

If you prefer to generate fonts manually, run the build in the tc-lib-pdf-font package:

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

Equivalent one-liner from your project root:

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

Once fonts are generated, they are cached in vendor/tecnickcom/tc-lib-pdf-font/target/fonts/ and will not be regenerated unless explicitly rebuilt.

You can also add your own fonts and generate their PHP font data with tc-lib-pdf-font. For shared or immutable environments, generate them once into a persistent directory you control (outside vendor/) and point K_PATH_FONTS to that location.

\define('K_PATH_FONTS', '/opt/app/fonts/tc-lib-pdf');

This avoids regenerating fonts on every dependency reinstall and lets multiple deployments reuse the same prepared font set.

Quick Start

<?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();

$font = $pdf->font->insert($pdf->pon, 'helvetica', '', 12);
$pdf->addPage();
$pdf->page->addContent($font['out']);

$html = '<h1>Hello, PDF!</h1><p>Generated with tc-lib-pdf.</p>';
$pdf->addHTMLCell($html, 15, 20, 180);

$raw = $pdf->getOutPDFString();
$pdf->renderPDF($raw);

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 Features

Text and Typography

  • Full UTF-8 Unicode and right-to-left (RTL) language support
  • TrueTypeUnicode, OpenTypeUnicode v1, TrueType, OpenType v1, Type1, and CID-0 fonts
  • Font subsetting to keep file sizes small
  • Text hyphenation, stretching, and letter-spacing (tracking)
  • Language-aware TeX hyphenation patterns and optional zero-width breakpoints
  • Text rendering modes: fill, stroke, and clipping
  • Automatic line breaks, page breaks, and justification

Layout and Rendering

  • All standard page sizes, custom formats, custom margins, and configurable units of measure
  • HTML and CSS rendering
  • SVG rendering
  • Multi-column layouts and no-write page regions
  • Headers, footers, and common page content
  • Bookmarks, named destinations, and table of contents
  • Automatic page numbering and page groups
  • Full page box control (Media/Crop/Bleed/Trim/Art), page reordering, and viewer preferences

Images and Graphics

  • Native JPEG, PNG, and SVG support
  • Extended image format handling via GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM, WBMP, TIFF, ICO, PSD, IFF, SWC)
  • Geometric graphics and 2D transformations
  • Linear and radial gradients, Coons patch mesh gradients, crop marks, and registration bars
  • JPEG and PNG ICC profiles, grayscale/RGB/CMYK/spot colors, transparencies, and overprint control

Security and Standards

  • Password and certificate-based document encryption (RC4 and AES, up to 256-bit)
  • Digital signatures — detached CMS (PKCS#7) signatures with configurable appearance fields
  • RFC 3161 TSA timestamps — embed a trusted timestamp token from any RFC 3161-compliant Time Stamping Authority (TSA) into the CMS signature; configurable digest algorithm (sha256, sha384, sha512), policy OID, nonce, timeout, and TLS peer verification
  • LTV (Long-Term Validation) — embed revocation evidence in the same PDF revision as the signature:
    • collects the signing certificate chain and fetches OCSP responses and/or CRL payloads from AIA and CDP URLs
    • deduplicates binary payloads by fingerprint
    • emits /DSS, /VRI, /OCSPs, /CRLs, and /Certs objects in the catalog
    • each feature (OCSP, CRL, cert embedding, DSS, VRI) can be enabled independently via setSignature() LTV options
  • PDF annotations: links, text notes, file attachments, markup, shapes, media, and widgets
  • JavaScript embedding
  • PDF/A (1/2/3, including a/b/u conformance levels) — see Factur-X / ZUGFeRD below
  • PDF/X (generic alias, PDF/X-1a, PDF/X-3, PDF/X-4, PDF/X-5) — print-exchange conformance: per-variant OutputIntent identifiers, GTS_PDFXVersion in Info dict and XMP, PDF version enforcement, CMYK color forcing for restrictive profiles (X-1a, X-3), transparency restrictions, and suppression of encryption and JavaScript
  • PDF/UA (generic alias, PDF/UA-1, PDF/UA-2) — accessibility conformance: tagged structure tree (StructTreeRoot / ParentTree), MarkInfo /Marked true, document language (/Lang), DisplayDocTitle true, ActualText for ligatures and special glyphs, figure alt-text tagging, and heading-level clamping to prevent skipped levels; PDF/UA-2 targets PDF 2.0

Advanced Workflows

  • 1D and 2D barcodes via tc-lib-barcode
  • Interactive AcroForm fields (buttons, checkboxes, radio buttons, text, combo boxes, list boxes)
  • XObject templates and layers with object visibility controls
  • Multiple output targets: inline display, forced download, file save, and MIME attachment
  • Factur-X / ZUGFeRD workflows via embedded XML in PDF/A-3 documents
  • Page compression via the zlib PHP extension

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:

  • tc-lib-pdf : Top-level PDF generation library; composes the full package stack.
  • tc-lib-barcode : Generates 1D and 2D barcodes (QR, Data Matrix, Code 128, and more).
  • tc-lib-color : Color conversion and management across RGB, CMYK, HSL, and spot color spaces.
  • tc-lib-file : File and data-URI helpers used internally for asset loading.
  • tc-lib-unicode : Unicode string processing: bidirectional text, normalization, and character utilities.
  • tc-lib-unicode-data : Raw Unicode character data tables used by tc-lib-unicode.
  • tc-lib-pdf-encrypt : PDF encryption: RC4 and AES (up to 256-bit), permissions, and digital signatures.
  • tc-lib-pdf-filter : PDF stream filters: FlateDecode, ASCII85, LZW, and others.
  • tc-lib-pdf-font : Font loading, subsetting, and embedding for all supported font types.
  • tc-lib-pdf-graph : Vector graphics primitives: paths, transformations, gradients, and transparency.
  • tc-lib-pdf-image : Image loading and embedding: JPEG, PNG, SVG, and GD-backed formats.
  • tc-lib-pdf-page : Page geometry, margins, boxes, and page-level attributes.
  • tc-lib-pdf-parser : Reads and parses existing PDF files for import or manipulation.

Migration Path

  1. Keep legacy TCPDF stable in production while planning migration.
  2. Start new features on tc-lib-pdf.
  3. Move legacy document flows incrementally: one template, one module, or one service at a time.
  4. Validate outputs with your existing PDF regression checks.

Next Steps

If this project helps your work, please consider supporting development via PayPal.


© 2004-2026 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy