跳轉到

PDF/A-4 合規認證(ISO 19005-4)

PDF/A-4 是 PDF 長期保存格式的最新標準(ISO 19005-4:2020),建構於 PDF 2.0 之上。NextPDF Enterprise 提供原生的 PDF/A-4 產生與驗證能力,無需外部驗證服務。


PDF/A-4 子集

子集 說明 典型用途
PDF/A-4 基礎長期保存格式 靜態文件、合約
PDF/A-4e 支援工程資料(3D、CAD)嵌入 技術圖紙、BIM 模型
PDF/A-4f 允許嵌入任意關聯檔案 發票(ZUGFeRD)、附件文件

核心 API

PdfA4Builder

use NextPDF\Enterprise\Compliance\PdfA\PdfA4Builder;
use NextPDF\Enterprise\Compliance\PdfA\PdfA4Subset;
use NextPDF\Enterprise\Compliance\PdfA\OutputIntent;
use NextPDF\Enterprise\Compliance\PdfA\XmpMetadata;

$builder = PdfA4Builder::forSubset(PdfA4Subset::PdfA4f)
    ->withOutputIntent(
        OutputIntent::iccProfile(
            profilePath: '/icc/sRGB_v4_ICC_preference.icc',
            condition: 'sRGB',
            conditionIdentifier: 'Custom',
            registryName: 'http://www.color.org',
        )
    )
    ->withXmpMetadata(
        XmpMetadata::create()
            ->setTitle('Annual Report 2025')
            ->setCreator('ACME Corp')
            ->setCreationDate(new DateTimeImmutable('2025-01-15'))
            ->setConformance(PdfA4Subset::PdfA4f)
    );

$document = $builder->build($sourceDocument);

PHP Compatibility

This example uses PHP 8.5 syntax. If your environment runs PHP 8.1 or 7.4, use NextPDF Backport for a backward-compatible build.

OutputIntent

OutputIntent 定義文件的色彩空間描述,是 PDF/A 合規的必要條件。

use NextPDF\Enterprise\Compliance\PdfA\OutputIntent;

// ICC Profile 方式(推薦)
$intent = OutputIntent::iccProfile(
    profilePath: '/icc/sRGB_v4_ICC_preference.icc',
    condition: 'sRGB',
    conditionIdentifier: 'Custom',
    registryName: 'http://www.color.org',
);

// 標準 sRGB 快速建構
$intent = OutputIntent::sRgbDefault();

XmpMetadata

use NextPDF\Enterprise\Compliance\PdfA\XmpMetadata;
use NextPDF\Enterprise\Compliance\PdfA\PdfA4Subset;

$xmp = XmpMetadata::create()
    ->setTitle('Contract Agreement 2025-001')
    ->setCreator('Legal Department')
    ->setSubject('Service Agreement')
    ->setKeywords(['contract', 'legal', '2025'])
    ->setCreationDate(new DateTimeImmutable())
    ->setModificationDate(new DateTimeImmutable())
    ->setConformance(PdfA4Subset::PdfA4)
    ->setCustomProperty('acme:documentClass', 'LegalContract');

驗證

PdfA4Validator

use NextPDF\Enterprise\Compliance\PdfA\PdfA4Validator;
use NextPDF\Enterprise\Compliance\PdfA\ValidationResult;

$validator = new PdfA4Validator();
$result = $validator->validate($pdfBytes);

if (!$result->isConformant()) {
    foreach ($result->violations() as $violation) {
        // $violation->rule()       — 違規規則識別碼(如 "6.2.3")
        // $violation->severity()   — ERROR | WARNING
        // $violation->location()   — 物件參考(如 "obj 42 0")
        // $violation->description() — 人類可讀描述
        echo $violation->rule() . ': ' . $violation->description();
    }
}

常見違規規則參考

規則 ID 說明 修正方向
6.1.2 缺少 OutputIntent 加入 ICC Profile
6.1.7 使用禁止的動作類型 移除 JavaScript / Launch 動作
6.2.3 XMP 中繼資料格式錯誤 驗證 xmpMM:InstanceID 格式
6.3.1 字型未完整嵌入 使用 Font::embedFull()
6.5.3 透明度群組未標記 設定 Group.CS 為 DeviceRGB
7.1 加密與 PDF/A-4e 衝突 僅 PDF/A-4e 允許加密

PDF/A-4f 嵌入關聯檔案

PDF/A-4f 子集允許嵌入任意格式的關聯檔案(如 ZUGFeRD XML):

use NextPDF\Enterprise\Compliance\PdfA\AssociatedFile;

$builder = PdfA4Builder::forSubset(PdfA4Subset::PdfA4f)
    ->withAssociatedFile(
        AssociatedFile::create(
            fileSpec: 'zugferd-invoice.xml',
            mimeType: 'application/xml',
            content: $zugferdXmlBytes,
            relationship: AssociatedFile::RELATIONSHIP_ALTERNATIVE,
            description: 'ZUGFeRD 2.3 Invoice Data',
        )
    );

與 ZUGFeRD 整合

PDF/A-4f 是 ZUGFeRD 2.x 電子發票的必要容器格式:

// ZUGFeRD 章節有完整說明
// 參見:invoice/zugferd

詳見 ZUGFeRD 電子發票


效能考量

場景 預期開銷
PDF/A-4 基礎轉換(10 頁)
PDF/A-4 驗證(10 頁)
批次轉換(100 份文件)

延伸閱讀