Skip to content

アクセシブルPDF

タグ付き構造、代替テキスト、言語タグを使用して、スクリーンリーダーや支援技術で動作するアクセシブルなPDFを作成します。

PDFのアクセシビリティとは?

要件重要性
構造タグスクリーンリーダーが見出し/段落/リストタグをナビゲーションに使用
代替テキスト画像を見ることができないユーザーに画像を説明
言語タグテキストの読み上げ方法をリーダーに伝達
読み取り順序ビジュアルレイアウトとは独立した論理的順序
テーブルヘッダーデータセルを列/行のコンテキストに関連付け
ブックマーク長いドキュメントのキーボードナビゲーション

規格

規格範囲
PDF/UA-2(ISO 14289-2)PDFユニバーサルアクセシビリティ
WCAG 2.1Webコンテンツアクセシビリティガイドライン
Section 508米国連邦アクセシビリティ
EN 301 549EUアクセシビリティ要件

完全なコードサンプル

php
<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use TcpdfNext\Document;
use TcpdfNext\Enums\Alignment;
use TcpdfNext\Accessibility\TagManager;

// ── 1. タグ付きPDFを有効化 ───────────────────────────────────────────────
$pdf = Document::create()
    ->setTitle('Accessibility Report 2026')
    ->setAuthor('Acme Corp')
    ->setLanguage('en-US')
    ->setTagged(true)
    ->setDisplayDocTitle(true)
    ->addPage();

$tag = $pdf->getTagManager();

// ── 2. 見出し(H1) ───────────────────────────────────────────────────
$tag->beginTag('H1');
$pdf->setFont('helvetica', style: 'B', size: 24)
    ->cell(0, 14, 'Accessibility Report 2026', newLine: true);
$tag->endTag();

// ── 3. 段落 ──────────────────────────────────────────────────────
$tag->beginTag('P');
$pdf->setFont('times', size: 12)
    ->multiCell(0, 7, 'Acme Corp is committed to producing documents that '
        . 'meet PDF/UA and WCAG 2.1 AA standards, ensuring equal access '
        . 'for all users regardless of ability.');
$tag->endTag();

// ── 4. 小見出し(H2) ──────────────────────────────────────────────
$tag->beginTag('H2');
$pdf->setFont('helvetica', style: 'B', size: 18)
    ->cell(0, 12, 'Key Metrics', newLine: true);
$tag->endTag();

// ── 5. タグ付きリスト ────────────────────────────────────────────────
$items = [
    'Documents audited: 1,240',
    'Compliance rate: 98.7%',
    'Issues resolved: 412',
];

$tag->beginTag('L');
foreach ($items as $item) {
    $tag->beginTag('LI');

    $tag->beginTag('Lbl');
    $pdf->setFont('helvetica', size: 11)
        ->cell(8, 7, "\u{2022}");
    $tag->endTag(); // Lbl

    $tag->beginTag('LBody');
    $pdf->cell(0, 7, $item, newLine: true);
    $tag->endTag(); // LBody

    $tag->endTag(); // LI
}
$tag->endTag(); // L

// ── 6. 代替テキスト付き画像 ────────────────────────────────────────────
$tag->beginTag('Figure');
$pdf->image(
    file:    __DIR__ . '/assets/compliance-chart.png',
    x:       null,
    y:       null,
    width:   120,
    height:  null,
    altText: 'Bar chart showing compliance rate rising from 91% in 2023 '
           . 'to 98.7% in 2026 across four consecutive years.',
);
$tag->beginTag('Caption');
$pdf->setFont('helvetica', style: 'I', size: 9)
    ->cell(0, 6, 'Figure 1: Compliance trend 2023-2026', newLine: true);
$tag->endTag(); // Caption
$tag->endTag(); // Figure

// ── 7. 装飾要素をアーティファクトとして設定(スクリーンリーダーがスキップ) ─────
$tag->beginArtifact('Layout');
$pdf->setDrawColor(200, 200, 200)
    ->line(15, $pdf->getY(), 195, $pdf->getY());
$tag->endArtifact();

// ── 8. タグ付きテーブル ───────────────────────────────────────────────
$tag->beginTag('H2');
$pdf->setFont('helvetica', style: 'B', size: 18)
    ->cell(0, 12, 'Quarterly Results', newLine: true);
$tag->endTag();

$tag->beginTag('Table');

// ヘッダー行
$tag->beginTag('TR');
foreach (['Quarter', 'Audited', 'Passed', 'Rate'] as $header) {
    $tag->beginTag('TH', attributes: ['scope' => 'col']);
    $pdf->setFont('helvetica', style: 'B', size: 10)
        ->cell(45, 8, $header, border: 1);
    $tag->endTag();
}
$tag->endTag(); // TR

// データ行
$rows = [
    ['Q1', '310', '305', '98.4%'],
    ['Q2', '320', '316', '98.8%'],
    ['Q3', '305', '302', '99.0%'],
    ['Q4', '305', '301', '98.7%'],
];
foreach ($rows as $row) {
    $tag->beginTag('TR');
    foreach ($row as $i => $cell) {
        $tagName = $i === 0 ? 'TH' : 'TD';
        $attrs   = $i === 0 ? ['scope' => 'row'] : [];
        $tag->beginTag($tagName, attributes: $attrs);
        $pdf->setFont('times', size: 10)
            ->cell(45, 8, $cell, border: 1);
        $tag->endTag();
    }
    $tag->endTag(); // TR
}
$tag->endTag(); // Table

// ── 9. 外国語テキストの言語タグ ──────────────────────────────────
$tag->beginTag('P', attributes: ['lang' => 'de-DE']);
$pdf->setFont('times', size: 11)
    ->multiCell(0, 7, 'Barrierefreiheit ist ein grundlegendes Recht.');
$tag->endTag();

// ── 10. 保存 ──────────────────────────────────────────────────────
$pdf->save(__DIR__ . '/accessible-report.pdf');

echo 'Accessible PDF created.' . PHP_EOL;

HTML自動タグ付け

TCPDF-Nextはセマンティック HTMLから自動的に構造タグを生成できます:

php
$pdf = Document::create()
    ->setTagged(true)
    ->setLanguage('en-US')
    ->addPage();

$pdf->setAutoTagging(true)
    ->writeHtml(<<<'HTML'
        <h1>Report</h1>
        <p>Summary paragraph.</p>
        <img src="chart.png" alt="Revenue chart showing 15% growth" />
        <table>
            <tr><th>Q</th><th>Revenue</th></tr>
            <tr><td>Q1</td><td>$548M</td></tr>
        </table>
    HTML);
HTML要素PDFタグ
<h1>--<h6>H1--H6
<p>P
<img alt="...">Figure
<table>Table
<th>TH
<td>TD
<ul><ol>L
<li>LI
<a>Link

アクセシビリティチェックリスト

  • [ ] setTitle() -- ドキュメントタイトルが設定されている
  • [ ] setDisplayDocTitle(true) -- ビューアがファイル名ではなくタイトルを表示
  • [ ] setLanguage('en-US') -- ドキュメント言語が宣言されている
  • [ ] すべてのコンテンツが構造タグで囲まれている
  • [ ] 見出しが順番に並んでいる(H1、H2、H3 -- スキップなし)
  • [ ] すべての意味のある画像にaltTextがある
  • [ ] 装飾画像がアーティファクトとしてマーク済み
  • [ ] テーブルにscope属性付きのTHセルがある
  • [ ] 読み取り順序が論理的順序と一致
  • [ ] 色コントラスト比が4.5:1以上

バリデーション

bash
# PDF/UAバリデーションにはPAC(PDF Accessibility Checker)を使用
# https://pdfua.foundation/en/pac-download/

さらに詳しく

LGPL-3.0-or-later ライセンスの下で公開されています。