定制 tecnickcom/tc-lib-pdf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tecnickcom/tc-lib-pdf

Composer 安装命令:

composer require tecnickcom/tc-lib-pdf

包简介

PHP PDF Library

README 文档

README

TCPDF logo

The next generation of TCPDF - a modern, modular PHP library for programmatically generating PDF documents.

Latest Stable Version Build Coverage License Downloads

Sponsor on GitHub

💖 Keep TCPDF maintained. tc-lib-pdf is the actively-developed successor to TCPDF, which is installed 100M+ times across 500+ PHP packages and is now maintenance-only. If your company depends on it, become a sponsor to keep this shared infrastructure secure and maintained — see Sponsors for tiers.

Contents

Overview

tc-lib-pdf is a pure-PHP library for dynamically generating PDF documents.
It is the modern evolution of the widely used TCPDF library, redesigned around a modular package architecture, Composer-first workflow, and strict PHP type safety.

It coordinates specialized companion packages for fonts, images, graphics, pages, filtering, and encryption into a cohesive document-authoring API. The result is a production-ready toolkit for invoices, reports, labels, and other generated PDFs where predictable output and long-term maintainability matter.

Namespace \Com\Tecnick\Pdf
Author Nicola Asuni <info@tecnick.com>
License GNU LGPL v3 - see LICENSE
Website https://tcpdf.org
API docs https://tcpdf.org/docs/srcdoc/tc-lib-pdf
Packagist https://packagist.org/packages/tecnickcom/tc-lib-pdf

Releases follow Semantic Versioning:

  • PATCH — backwards-compatible bug fixes
  • MINOR — backwards-compatible new features
  • MAJOR — breaking changes

Sponsors

tc-lib-pdf is the actively-developed successor to TCPDF, which is installed 100M+ times across 500+ PHP packages and is now maintenance-only. If your product relies on TCPDF or tc-lib-pdf, sponsoring is how that shared infrastructure stays secure and maintained — closer to insurance on a dependency you already ship than to a donation.

Sponsor on GitHub

Your logo here. Be the first company to back the project — become a sponsor →

See SPONSORS.md for sponsorship tiers, how to add your logo, and the logo/content policy. Individual backers are listed in BACKERS.md.

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 quick-start steps below, then compare the runnable examples in examples/index.md with the equivalent workflows you already maintain in TCPDF.

Features

Text & Fonts

  • 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 & Content

  • 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
  • Per-page transparency group control via setPageTransparencyGroup() — by default ('auto') the page transparency /Group is emitted only on pages that actually blend, flattening fully-opaque pages for faster, more predictable printing on conservative RIPs/firmware; 'always' keeps the group on every page (legacy) and 'never' drops it entirely

Images & 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 & Standards

  • Password and certificate-based document encryption (RC4 and AES, up to 256-bit)
  • Remote resource controls via fileOptions with host allowlists plus separate internal and markup local-path allowlists for external assets
  • 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 doc/STANDARDS.md and E001_invoice.php for a Factur-X / ZUGFeRD example
  • 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

PDF Import

  • Import pages from existing PDFs as Form XObjects and place them on any destination page
  • Import a single page at a user-defined position and scale (importPage / useImportedPage)
  • Append full documents page-by-page, auto-sized to the source page dimensions (addPageFromImport)
  • Load source PDFs from a file path or raw byte string (setImportSourceFile / setImportSourceData)

Other

  • 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

Requirements

  • PHP 8.2 or later
  • 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 companion font files (see doc/FONTS.md).
  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"
    }
}

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,   // mm from left page edge
    posy:   20,   // mm from top page edge
    width:  180,  // mm wide (0 = to right margin)
);

$rawpdf = $pdf->getOutPDFString();

$pdf->renderPDF($rawpdf);

getOutPDFString() returns the raw PDF bytes. renderPDF() streams those bytes to the browser; if you need file storage or an email attachment, keep the returned string and write or hand it off yourself.

Note: realpath() returns false when the fonts directory does not yet exist. If you see K_PATH_FONTS errors on first run, verify that fonts were generated after composer install (see doc/FONTS.md).

For more complete examples — including invoices, images, barcodes, HTML tables, dedicated HTML selector/form/table showcases, PDF/X, and PDF/UA — see the examples directory. Annotation-focused runnable example: examples/E027_annotations.php.

To run the bundled examples locally:

make x       # build example assets
make server  # start a local PHP server

Then open http://localhost:8971/index.php.

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.

Examples

The examples directory is the fastest way to understand supported features and integration patterns in runnable form.

Useful starting points:

Selected topic groups in the examples set:

  • Document basics (layout, headers/footers, cells, colors, images, text rendering)
  • Standards and compliance (PDF/X, PDF/UA, PDF/A workflows)
  • Security and signing (encryption, signatures, timestamps, LTV)
  • Advanced composition (annotations, templates, layers, page import/reorder)

To preview examples locally:

make x
make server

Then open http://localhost:8971/index.php.

In-Depth Documentation

For implementation details, compliance guidance, operational workflows, and advanced usage patterns, see the focused guides in the doc/ directory:

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.

tecnickcom/tc-lib-pdf 适用场景与选型建议

tecnickcom/tc-lib-pdf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 548.65k 次下载、GitHub Stars 达 1.89k, 最近一次更新时间为 2016 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「pdf」 「document」 「TCPDF」 「PDFD32000-2008」 「tc-lib-pdf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tecnickcom/tc-lib-pdf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tecnickcom/tc-lib-pdf 我们能提供哪些服务?
定制开发 / 二次开发

基于 tecnickcom/tc-lib-pdf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 548.65k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1894
  • 点击次数: 67
  • 依赖项目数: 16
  • 推荐数: 3

GitHub 信息

  • Stars: 1886
  • Watchers: 152
  • Forks: 255
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2016-07-10