Skip to content

PDF/UA アクセシビリティ

PDF/UA (ISO 14289) はユニバーサルにアクセス可能な PDF ドキュメントの要件を定義します。 PDF Oxide は構造ツリー、見出しシーケンス、代替テキスト、テーブルヘッダー、言語宣言などを検証します。

サポートされるレベル

Level Standard 説明
PDF/UA-1 ISO 14289-1:2014 基本アクセシビリティ要件
PDF/UA-2 ISO 14289-2:2024 強化された要件、WCAG 2.1に準拠

簡易バリデーション

from pdf_oxide import PdfDocument

doc = PdfDocument("document.pdf")
result = doc.validate_pdf_ua()
print(f"Valid: {result.valid}")
for error in result.errors:
    print(f"  {error}")
use pdf_oxide::PdfDocument;
use pdf_oxide::compliance::{validate_pdf_ua, PdfUaLevel};

let mut doc = PdfDocument::open("accessible.pdf")?;
let result = validate_pdf_ua(&mut doc, PdfUaLevel::UA1)?;

if result.has_errors() {
    println!("Not PDF/UA-1 compliant:");
    for error in &result.errors {
        println!("  [{}] {} (clause {})",
            error.code, error.message,
            error.clause.as_deref().unwrap_or("n/a"));
    }
} else {
    println!("Document is PDF/UA-1 compliant");
}

バリデータ API

PdfUaValidator ビルダーで特定のチェックを設定できます:

use pdf_oxide::PdfDocument;
use pdf_oxide::compliance::{PdfUaValidator, PdfUaLevel};

let mut doc = PdfDocument::open("report.pdf")?;

let result = PdfUaValidator::new()
    .check_heading_sequence(true)
    .check_color_contrast(true)
    .allow_custom_types(vec!["Caption".into(), "Aside".into()])
    .validate(&mut doc, PdfUaLevel::UA1)?;

println!("Errors: {}", result.errors.len());
println!("Warnings: {}", result.warnings.len());
println!("Structure elements checked: {}",
    result.stats.structure_elements_checked);

設定オプション

Method Default 説明
check_heading_sequence(bool) true H1-H6がレベルをスキップしないことを検証
check_color_contrast(bool) true 潜在的なコントラストの問題をフラグ
allow_custom_types(Vec<String>) [] 非標準構造タイプを警告なしで許可

構造ツリーの検査

バリデーション実行前に、ドキュメントの構造ツリーとマーク情報を検査できます:

use pdf_oxide::PdfDocument;

let mut doc = PdfDocument::open("tagged.pdf")?;

// Check if the document claims to be tagged
let mark_info = doc.mark_info()?;
println!("Marked: {}", mark_info.marked);
println!("Suspects: {}", mark_info.suspects);

// Access the structure tree
if let Some(tree) = doc.structure_tree()? {
    println!("Root tag: {}", tree.root_type);
    println!("Children: {}", tree.children.len());
}

mark_info() メソッドの戻り値:

Field Type 説明
marked bool ドキュメントがタグ付きと宣言しているか
suspects bool タグ割り当てが不正確な可能性があるか
user_properties bool ユーザープロパティが存在するか

suspectstrue の場合、PDF Oxideは信頼性の低い構造ツリーに依存する代わりに、テキスト抽出で幾何学的順序に自動フォールバックします。

検証される項目

The validator covers the following PDF/UA requirements:

ドキュメントレベル

Check Clause 説明
Language 7.2 カタログに /Lang エントリが存在
Title 7.1 ドキュメントタイトルが設定され、タイトルバーに表示
Tagged 7.1 MarkInfo辞書が Marked = true を宣言
XMP metadata 7.1 XMPストリームに pdfuaid:part が宣言

構造

Check Clause 説明
Structure tree 7.1 StructTreeRootをルートとする完全な構造ツリー
Role mapping 7.5 非標準タイプが標準構造要素にマッピング
Heading hierarchy 7.4.2 見出し(H1-H6)がレベルをスキップしない
Artifact marking 7.3 装飾コンテンツがアーティファクトとしてマーク
Reading order 7.2 構造ツリーが論理的な読み順を定義

コンテンツ

Check Clause 説明
Alt text for images 7.3 Figure要素の /Alt または /ActualText
Table headers 7.5 テーブル構造に TH 要素が存在
Form labels 7.6.2 フォームフィールドに関連ラベルまたはツールチップ
Link text 7.18 リンクアノテーションに説明的なコンテンツ
List structure 7.4.3 リストが LLILblLBody 構造を使用

フォントとテキスト

Check Clause 説明
Unicode mapping 7.21.3 すべてのテキストにUnicode表現
Font embedding 7.21.4 フォント埋め込みまたは標準Base14フォント
ActualText 7.21.5 合字と特殊グリフに /ActualText

UaValidationResult

pub struct UaValidationResult {
    pub level: PdfUaLevel,
    pub errors: Vec<UaComplianceError>,
    pub warnings: Vec<ComplianceWarning>,
    pub stats: UaValidationStats,
}

UaComplianceError

Each error includes optional WCAG alignment:

pub struct UaComplianceError {
    pub code: UaErrorCode,
    pub message: String,
    pub location: Option<String>,
    pub wcag_ref: Option<String>,
    pub clause: Option<String>,
}

wcag_ref フィールドはPDF/UA違反を対応するWCAG成功基準にマッピングします (e.g., "1.1.1" 非テキストコンテンツ用, "1.3.1" 情報と関係用).

UaErrorCode Categories

The UaErrorCode enum includes error categories such as:

  • MissingLanguage – ドキュメントカタログに /Lang エントリなし
  • MissingStructureTree – ドキュメントがタグ付きでない
  • MissingAltText – Figure要素に代替テキストなし
  • HeadingSkipped – 見出しレベルのジャンプ(例:H1からH3)
  • MissingTableHeaders – テーブルに TH 要素なし
  • FormFieldNoLabel – フォームフィールドに関連ラベルなし
  • InvalidRoleMapping – 非標準タイプが標準要素にマッピングされていない
  • ArtifactNotMarked – 装飾コンテンツがアーティファクトとしてマークされていない
  • MissingUnicode – Unicodeマッピングのないテキスト

実践例: Accessibility Report

Generate a human-readable accessibility report from validation results:

use pdf_oxide::PdfDocument;
use pdf_oxide::compliance::{validate_pdf_ua, PdfUaLevel};

let mut doc = PdfDocument::open("document.pdf")?;
let result = validate_pdf_ua(&mut doc, PdfUaLevel::UA1)?;

println!("=== PDF/UA Accessibility Report ===");
println!("Level: PDF/UA-{}", result.level.xmp_part());
println!("Status: {}", if result.has_errors() { "FAIL" } else { "PASS" });
println!();

if result.has_errors() {
    println!("Errors ({}):", result.errors.len());
    for (i, error) in result.errors.iter().enumerate() {
        print!("  {}. [{}] {}", i + 1, error.code, error.message);
        if let Some(ref wcag) = error.wcag_ref {
            print!("  (WCAG {})", wcag);
        }
        println!();
    }
}

if result.has_warnings() {
    println!("\nWarnings ({}):", result.warnings.len());
    for warning in &result.warnings {
        println!("  - [{}] {}", warning.code, warning.message);
    }
}

println!("\nStats:");
println!("  Structure elements checked: {}",
    result.stats.structure_elements_checked);

次のステップ