Skip to content

Triết lý thiết kế

TCPDF-Next lấy cảm hứng từ TCPDF nhưng là bản viết lại hoàn toàn từ đầu cho kỷ nguyên PHP hiện đại. Nó không phải fork, không phải nâng cấp dần — nó là thư viện hoàn toàn mới xây trên kiến trúc thế hệ tiếp theo.

TCPDF gốc phục vụ cộng đồng PHP tốt hơn một thập kỷ. Nhưng kiến trúc file đơn, 30,000 dòng không thể hỗ trợ yêu cầu tạo PDF hiện đại: tuân thủ PDF 2.0, chữ ký số PAdES, lưu trữ PDF/A-4, hay tích hợp với framework như Laravel.

TCPDF-Next giữ các khái niệm lập trình viên PHP quen — addPage(), cell(), setFont() — trong khi xây lại mọi thứ bên dưới để đáp ứng tiêu chuẩn 2026.

Nhìn tổng quan

TCPDF gốcTCPDF-Next
Phiên bản PHP5.x -- 8.xChỉ 8.5+
Đặc tả PDF1.4 -- 1.72.0 (ISO 32000-2:2020)
Kiến trúcClass đơn ~30K dòng213 file, 26 module, 12 trait composable
Type safetyKhôngPHPStan Level 10, backed enum, readonly class
Chữ kýPKCS#7 cơ bảnPAdES B-B (Core) đến B-LTA (Pro)
Lưu trữPDF/A-1b (một phần)PDF/A-4 (ISO 19005-4:2020)
Render HTMLTích hợp (CSS hạn chế)Tích hợp + Chrome CDP (CSS3 đầy đủ)
Testing~50 test908+ test, 28,881+ assertion
Mở rộngKế thừa monolithHệ sinh thái module + extension API

Kiến trúc hệ sinh thái

TCPDF-Next không phải monolith. Nó là hệ sinh thái module gồm bốn package, mỗi package có trách nhiệm rõ ràng:

Core TCPDF-Next
Core
Chức năng
Core Core
PDF 2.0 Engine
Artisan Artisan
Chrome CDP
Pro Pro
Doanh nghiệp
Tích hợp framework
Laravel Laravel
Laravel 12
Symfony Symfony
Symfony 7
CodeIgniter CodeIgniter
CodeIgniter 4
Tương thích
Adaptation Adaptation
Chuyển đổi từ TCPDF
  • Core (148 file) — Engine PDF. Mọi thứ bạn cần cho tạo document, typography, barcode, mã hóa và chữ ký PAdES B-B.
  • Artisan (17 file) — Tích hợp Chrome CDP cho render HTML/CSS3 pixel-perfect. Output PDF có thể chọn text qua Form XObject, không phải ảnh raster.
  • Laravel (4 file) — Tích hợp framework không cần cấu hình. Facade, HTTP response, queue job, binding an toàn cho Octane.
  • Pro (47 file) — Tính năng enterprise. PAdES B-T đến B-LTA, PDF/A-4, ký HSM, barcode chuyên biệt.

Extension API mở: lập trình viên bên thứ ba có thể xây extension riêng hook vào Core qua interface đã publish (PdfDocumentInterface, SignerInterface, FontManagerInterface, HsmSignerInterface).

12 Trait Composable

Class Document là điểm vào duy nhất. Thay vì class monolithic, chức năng được compose từ 12 trait tập trung:

TraitTrách nhiệm
HasMetadataTiêu đề, tác giả, chủ đề, từ khóa, ngôn ngữ
HasPagesQuản lý trang, kích thước, margin, nhóm trang
HasTypographyTải font, kích thước, trang trí văn bản, RTL, BiDi
HasColorsRGB, CMYK, spot color, alpha, blend mode
HasTextOutputcell(), multiCell(), text(), write(), writeHtml()
HasDrawingHình dạng, gradient, pattern, SVG, EPS, hình ảnh
HasTransformsScale, rotate, translate, skew, mirror
HasLayoutHeader, footer, cột, booklet
HasNavigationBookmark, link, TOC, annotation, đính kèm file
HasInteractiveTrường form, layer, template, JavaScript
HasSecurityMã hóa, chữ ký số, tagged PDF, BiDi, linearization
HasOutputoutput(), save(), getPdfData(), streaming

Mọi public method trả về static cho fluent chaining:

php
$pdf = Document::create()
    ->setTitle('Invoice')       // HasMetadata
    ->addPage()                 // HasPages
    ->setFont('Helvetica', '', 12) // HasTypography
    ->setFillColor(240, 240, 240)  // HasColors
    ->cell(0, 10, 'Hello')     // HasTextOutput
    ->save('invoice.pdf');      // HasOutput

Tiếp theo

Phân phối theo giấy phép LGPL-3.0-or-later.