跳轉到

文件中繼資料

NextPDF 支援 PDF DocInfo 字典與 XMP 中繼資料串流兩種中繼資料格式,並在輸出時自動保持兩者同步。對於需要 PDF/A-4 合規的場景,XMP 是唯一有效的中繼資料載體。

基本中繼資料

最常用的中繼資料欄位可直接透過 Configuration 設定:

use NextPDF\Core\Configuration;

$config = Configuration::create(
    title: 'Annual Report 2026',
    author: 'Acme Corp Finance Team',
    subject: 'Financial Results for FY2026',
    keywords: ['finance', 'annual-report', '2026', 'acme'],
    creator: 'Acme Reporting System v3.0',
    producer: 'NextPDF Core',
);

執行期設定中繼資料

建立文件後仍可在 finalize() 前修改中繼資料:

use NextPDF\Core\Metadata;

$document->metadata()->set(
    Metadata::TITLE, 'Invoice #2026-001'
);

$document->metadata()->setCreationDate(new DateTimeImmutable());
$document->metadata()->setModificationDate(new DateTimeImmutable());

自訂 XMP 中繼資料

對於標準欄位以外的自訂屬性,使用 XMP 命名空間擴充:

use NextPDF\Core\Metadata\XmpNamespace;

$document->metadata()->xmp()->addNamespace(
    prefix: 'acme',
    uri: 'https://acme.example.com/pdf-meta/1.0/',
);

$document->metadata()->xmp()->set(
    namespace: 'acme',
    property: 'invoiceId',
    value: 'INV-2026-001',
);

$document->metadata()->xmp()->set(
    namespace: 'acme',
    property: 'customerId',
    value: 'CUST-12345',
);

語言設定

// 設定文件主要語言(影響 PDF/UA 合規性)
$document->metadata()->setLanguage('zh-TW');

XMP 封包格式

NextPDF 輸出的 XMP 封包遵循 ISO 16684-1,使用 UTF-8 編碼且包含標準填充:

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <!-- ... -->
  </rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>

參見

  • 設定 — 設定層級的中繼資料欄位
  • Tagged PDF — 無障礙中繼資料需求
  • PDF/UA — ISO 14289-2 中繼資料規範