跳到內容

安裝 NextPDF compat-legacy

nextpdf/compat-legacy 是一個 Composer 函式庫。它需要 PHP 8.4 或更新版本,以及 nextpdf/core ^3.0。安裝它不會變更你既有的 TCPDF 呼叫;它會新增一個可供切換使用的類別。

相依套件版本單一可信來源
PHP>=8.4 <9.0套件 composer.jsonrequire.php
nextpdf/core^3.0套件 composer.jsonrequire
Composer2.7 或更新版本工具鏈基準

此套件宣告採用 PHPStan Level 10 且不使用 baseline,並隨附自己的測試套件。它在執行階段需要 PHP 8.4。NextPDF 引擎本身透過 backport 系列支援 PHP 8.1 至 8.4,但此轉接器將 PHP 8.4 設為下限。

使用 Composer 加入此套件:

Terminal window
composer require nextpdf/compat-legacy:^3.0

Composer 會將 nextpdf/core ^3.0 解析為遞移相依套件。核心功能集不需要其他執行階段擴充功能。

此套件的中繼資料也會透過 Composer 的 replace 項目回應歷史名稱 nextpdf/compat-tcpdf。新的安裝應改為要求 nextpdf/compat-legacy;這是正規的套件名稱。

安裝後,確認轉接器類別可以載入,且引擎連結可以解析。以下檢查會完全在記憶體中產生一份單頁 PDF,並驗證 PDF 標頭;這與套件測試 tests/Unit/Compat/Tcpdf/TcpdfOutputTest.php 所驗證的是同一個介面。

examples/install-verify.php
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use NextPDF\Compat\Tcpdf\TCPDF;
$pdf = new TCPDF('P', 'mm', 'A4');
$pdf->AddPage();
$pdf->SetFont('helvetica', '', 12);
$pdf->Cell(0, 10, 'compat-legacy install verified');
$bytes = $pdf->Output('verify.pdf', 'S');
if (! str_starts_with($bytes, '%PDF')) {
fwrite(STDERR, "Install check failed: output is not a PDF.\n");
exit(1);
}
echo "OK: adapter loaded, engine linked, PDF produced (" . strlen($bytes) . " bytes).\n";

執行檢查:

Terminal window
php examples/install-verify.php

預期輸出為單獨一行 OK:。回傳字串開頭出現 %PDF 前綴,即可確認轉接器已建構出 NextPDF\Core\Document、已委派頁面與文字呼叫,並序列化出有效的 PDF 2.0 輸出。

此轉接器需要 nextpdf/core ^3.0。確認解析後的版本:

Terminal window
composer show nextpdf/core --format=json

若 Composer 解析出的核心版本落在 ^3.0 之外,此轉接器會在建構時快速失敗,而不會產生錯誤的輸出。若你的專案也直接相依於該引擎,請在你的 composer.json 中明確鎖定引擎版本。

若你的程式碼庫仍呼叫全域命名空間中的 new \TCPDF(...),而你尚無法變更那些 use/require 行,此套件可以註冊全域別名。這是選擇性啟用的功能,並在 /integrations/tcpdf-compat/boot-and-discovery/. 中說明。若同一行程中也安裝了真正的 TCPDF 函式庫,請勿啟用它;衝突避免規則請參見 /integrations/tcpdf-compat/troubleshooting/。

  • 它不會修改或移除既有的 TCPDF 相依套件。移除 tecnickcom/tcpdf 是 /integrations/tcpdf-compat/migration/. 中刻意安排的後續步驟。
  • 它不會啟用數位簽章或 PDF/A。這些功能需要商業版的 NextPDF 版本(參見 /integrations/tcpdf-compat/security-and-operations/)。
  • 它不會變更 PDF 輸出目標。輸出一律為 PDF 2.0。
  • /integrations/tcpdf-compat/quickstart/ — 建立你的第一份實際文件。
  • /integrations/tcpdf-compat/configuration/ — 嚴格模式與轉接器設定。
  • /integrations/tcpdf-compat/migration/ — 逐檔的遷移策略。
  • /integrations/tcpdf-compat/method-coverage/ — 每個 TCPDF 方法在此的實際行為。
  • 套件 composer.json — 權威的相依套件限制條件
  • docs/TCPDF_COVERAGE.md — 權威的涵蓋矩陣(在 repo 內)