Validate tag structure, alt text, reading order, and language declarations. Produce PDFs that pass screen readers and meet government accessibility mandates.
use pdfluent::{Document, accessibility::{AltText, Standard, Validator}};
fn check_and_fix_accessibility(path: &str) -> anyhow::Result<()> {
let mut doc = Document::open(path)?;
// Validate against PDF/UA-1 (ISO 14289-1)
let validator = Validator::new(Standard::PdfUa1);
let report = validator.validate(&doc)?;
println!("{} violation(s):", report.violations().len());
for v in report.violations() {
println!(" [{}] {}", v.clause(), v.message());
}
// Add alt text to untagged images
for mut img in doc.images_without_alt_text() {
img.set_alt_text(AltText::new("Decorative figure"))?;
}
doc.save(path)?;
Ok(())
}Run cargo add pdfluent to get started.
Validate every clause in the PDF/UA-1 standard. PDFluent checks that every structural element is tagged, that the logical reading order matches the visual order, and that metadata declares a natural language.
Inspect the tag tree for missing or incorrect element types. Identify content streams that fall outside the tag tree. PDFluent can automatically tag plain paragraph and heading content in programmatically-generated PDFs.
Enumerate all Figure elements and identify those missing /Alt text. Set alternative text programmatically for images generated by your application. Decorative images can be marked as Artifact to suppress them from the accessibility tree.
The logical reading order in the tag tree must match the intended reading sequence. PDFluent detects common ordering inversions that cause screen readers to read content out of sequence.
Tables must associate data cells with header cells using TH elements and scope attributes. PDFluent validates these associations and reports missing or incorrect scope values.
PDF/UA-1 requires a natural language declaration at the document level and on elements in a different language from the document default. PDFluent validates /Lang entries and can set them automatically.