Bắt đầu
TCPDF-Next là thư viện PHP 8.5+ hiện đại dùng để tạo tài liệu PDF 2.0. Hướng dẫn này giúp bạn tạo PDF đầu tiên trong 5 phút.
Yêu cầu hệ thống
| Yêu cầu | Tối thiểu |
|---|---|
| PHP | 8.5+ |
| Extension | openssl, zlib, mbstring, gd, curl, intl |
| Composer | 2.x |
Cài đặt
bash
composer require yeeefang/tcpdf-nextLệnh này cài đặt package Core với toàn bộ 220+ file mã nguồn.
Package tùy chọn
bash
# Chrome CDP HTML renderer (CSS3 chính xác đến từng pixel)
composer require yeeefang/tcpdf-next-artisan
# Tích hợp framework
composer require yeeefang/tcpdf-next-laravel # Laravel 12
composer require yeeefang/tcpdf-next-symfony # Symfony 7
composer require yeeefang/tcpdf-next-codeigniter # CodeIgniter 4
# Adapter tương thích ngược TCPDF 6.2.13
composer require yeeefang/tcpdf-next-adaptation
# Tính năng doanh nghiệp (giấy phép thương mại)
composer require yeeefang/tcpdf-next-proPDF đầu tiên
php
<?php
require 'vendor/autoload.php';
use Yeeefang\TcpdfNext\Core\Document;
$pdf = Document::createStandalone()
->setTitle('My First PDF')
->setAuthor('TCPDF-Next')
->addPage()
->setFont('Helvetica', '', 16)
->cell(0, 10, 'Hello, PDF 2.0!')
->ln()
->setFont('Helvetica', '', 12)
->cell(0, 10, 'Generated with TCPDF-Next')
->save('hello.pdf');
echo "PDF saved to hello.pdf\n";Chạy thử:
bash
php hello.phpLuồng tạo PDF
Bước tiếp theo
- Cài đặt — Yêu cầu hệ thống, kiểm tra extension, thiết lập Docker
- Cấu hình — Thiết lập mặc định, đường dẫn font, tùy chọn mã hóa
- Sử dụng cơ bản — Trang, văn bản, font, hình ảnh và xuất file
- Package Core — Tài liệu đầy đủ về 220+ file mã nguồn
- Tích hợp Laravel — Facade, response, queue job
- Tích hợp Symfony — Bundle, PdfFactory, Messenger
- Tích hợp CodeIgniter — Services, Library, Queue
- Di chuyển từ TCPDF — Adapter thay thế trực tiếp cho TCPDF 6.2.13