Skip to content

PDF/A-4 歸檔

Pro — Commercial License Required
PDF/A-4 歸檔功能需要 Pro 套件。

PDF/A-4 是基於 PDF 2.0 的最新歸檔標準(ISO 19005-4:2020),旨在確保文件能在數十年後仍可被完整重現。Pro 套件提供完整的 PDF/A-4 合規管線,涵蓋中繼資料、色彩設定與合規性驗證。

核心類別

類別說明
PdfAManagerPDF/A 合規流程管理器
PdfAVersionPDF/A 版本列舉(A4、A4f、A4e)
XmpMetadataXMP 中繼資料產生器
OutputIntent輸出意圖定義
IccProfileICC 色彩設定檔載入器

PdfAVersion 版本列舉

說明
PdfAVersion::A4PDF/A-4 基本合規
PdfAVersion::A4fPDF/A-4f,允許嵌入任意格式檔案
PdfAVersion::A4ePDF/A-4e,允許嵌入 3D 工程資料

啟用 PDF/A-4

php
use Yeeefang\TcpdfNext\Core\Document;
use Yeeefang\TcpdfNext\Pro\Archive\PdfAManager;
use Yeeefang\TcpdfNext\Pro\Archive\PdfAVersion;
use Yeeefang\TcpdfNext\Pro\Archive\OutputIntent;
use Yeeefang\TcpdfNext\Pro\Archive\IccProfile;

$pdf = Document::create();

$manager = new PdfAManager($pdf);
$manager->enable(PdfAVersion::A4);

$manager->setOutputIntent(
    OutputIntent::create()
        ->subtype('GTS_PDFA1')
        ->outputConditionIdentifier('sRGB IEC61966-2.1')
        ->registryName('http://www.color.org')
        ->info('sRGB IEC61966-2.1')
        ->iccProfile(IccProfile::sRGB())
);

$pdf->addPage()
    ->font('Helvetica', size: 12)
    ->text('此文件符合 PDF/A-4 歸檔標準。')
    ->save('/output/pdfa4.pdf');

XmpMetadata

PDF/A-4 要求文件包含 XMP 中繼資料,且必須包含 PDF/A 識別資訊(pdfaid:part=4)。

php
use Yeeefang\TcpdfNext\Pro\Archive\XmpMetadata;

$xmp = XmpMetadata::create()
    ->title('年度財務報告')
    ->author('財務部')
    ->description('2025 年度經審計之財務報表')
    ->subject(['財務', '年報', '審計'])
    ->language('zh-TW')
    ->creatorTool('TCPDF-Next Pro v1.0')
    ->createDate('2025-03-15T10:00:00+08:00');

$manager->setXmpMetadata($xmp);

自訂命名空間

php
$xmp->addCustomNamespace(
    prefix: 'invoice',
    uri: 'urn:example:invoice:1.0',
    properties: [
        'invoiceNumber' => 'INV-2025-001',
        'totalAmount'   => '150000',
        'currency'      => 'TWD',
    ]
);

OutputIntent 與 IccProfile

OutputIntent 定義文件的預期輸出色彩條件,是 PDF/A 合規的必要條件。

內建 ICC 設定檔

php
use Yeeefang\TcpdfNext\Pro\Archive\IccProfile;

$srgb = IccProfile::sRGB();             // sRGB IEC61966-2.1
$cmyk = IccProfile::coatedFOGRA39();    // Coated FOGRA39
$custom = IccProfile::fromFile('/path/to/custom.icc');

CMYK 輸出意圖

php
$manager->setOutputIntent(
    OutputIntent::create()
        ->subtype('GTS_PDFA1')
        ->outputConditionIdentifier('FOGRA39')
        ->registryName('http://www.color.org')
        ->info('Coated FOGRA39 (ISO 12647-2:2004)')
        ->iccProfile(IccProfile::coatedFOGRA39())
);

驗證規則

PdfAManager 在輸出前會自動檢查合規性。以下是常見的驗證規則:

規則說明嚴重性
必須有 OutputIntent文件必須定義輸出意圖錯誤
必須有 XMP 中繼資料包含 PDF/A 識別資訊錯誤
禁止加密PDF/A 不允許任何形式的加密錯誤
字型必須嵌入所有字型都必須完整嵌入或子集化錯誤
禁止外部參照不可參照外部內容錯誤
交叉參考必須使用串流PDF 2.0 要求使用交叉參考串流錯誤
透明度需要混合色彩空間使用透明度時需有 OutputIntent警告

手動驗證

php
$result = $manager->validate();

if ($result->isCompliant()) {
    echo "文件符合 PDF/A-4 標準\n";
} else {
    foreach ($result->violations() as $v) {
        echo "[{$v->clause()}] {$v->message()}\n";
    }
}

結合 PDF/A-4 與數位簽章

PDF/A 禁止加密,但允許數位簽章。結合 PAdES B-LTA 簽章可建立具法律效力的歸檔文件:

php
$manager = new PdfAManager($pdf);
$manager->enable(PdfAVersion::A4);
$manager->setOutputIntent(/* ... */);

$signer = new DigitalSigner($cert);
$signer->level(SignatureLevel::PAdES_B_LTA);
$signer->timestampAuthority($tsa);

LtvManager::embed($pdf, $signer);
$pdf->save('/output/pdfa4-signed.pdf');

下一步

以 LGPL-3.0-or-later 授權釋出。