A guide for developers using PDFluent to build accessible, standards-compliant PDFs that remain valid for decades.
Long-term PDF archiving with PDFluent. Convert documents to PDF/A-1b, PDF/A-2b, and PDF/A-3b for compliance with ISO 19005 and EU archiving mandates.
use pdfluent::{PdfDocument, PdfAProfile, CompressOptions};
fn main() -> pdfluent::Result<()> {
let mut doc = PdfDocument::open("report.pdf")?;
// Check PDF/A conformance for long-term archiving
let report = doc.validate_pdfa(PdfAProfile::A2b)?;
println!("PDF/A-2b compliant: {}", report.is_compliant());
for v in &report.violations {
println!("[{}] {}", v.rule, v.message);
}
// Subset fonts and compress for a smaller archival file
doc.subset_fonts()?;
doc.compress(CompressOptions::archival())?;
doc.save("report-archival.pdf")?;
Ok(())
}Turn ordinary PDFs into ISO-compliant PDF/A-1b, PDF/A-2b, or PDF/A-3b files for long-term archiving. Embed fonts, fix color profiles, and attach files automatically.
use pdfluent::{PdfDocument, compliance::PdfALevel};
fn convert_to_archival(input: &str, output: &str) -> anyhow::Result<()> {
let mut doc = PdfDocument::open(input)?;
// Convert to PDF/A-2b — auto-embeds fonts and attaches sRGB color profile
let report = doc.convert_to_pdf_a(PdfALevel::A2b)?;
if !report.warnings().is_empty() {
for w in report.warnings() {
eprintln!("Warning: {}", w);
}
}
doc.save(output)?;
println!("Saved PDF/A-2b to {output}");
Ok(())
}Validate PDF/A conformance with zero false negatives. Full ISO 19005 support for PDF/A-1, 2, and 3 with detailed preflight reports.
use pdfluent::{PdfDocument, PdfAProfile};
fn main() -> pdfluent::Result<()> {
let doc = PdfDocument::open("archive.pdf")?;
let report = doc.validate_pdfa(PdfAProfile::A2b)?;
println!("Compliant: {}", report.is_compliant());
println!("Violations: {}", report.violations.len());
for v in &report.violations {
println!("[{}] {} (page {:?})", v.rule, v.message, v.page);
}
Ok(())
}Check PDFs against PDF/A, PDF/UA, and PDF/X standards. Get machine-readable violation reports. Enforce standards in CI/CD pipelines and batch workflows.
use pdfluent::{PdfDocument, PdfAProfile};
fn main() -> pdfluent::Result<()> {
let doc = PdfDocument::open("document.pdf")?;
let report = doc.validate_pdfa(PdfAProfile::A2b)?;
if report.is_compliant() {
println!("PDF/A-2b compliant");
} else {
for v in &report.violations {
println!("[{}] {}", v.rule, v.message);
}
}
Ok(())
}Validate tag structure, alt text, reading order, and language declarations. Produce PDFs that pass screen readers and meet government accessibility mandates.
use pdfluent::{PdfDocument, accessibility::{AltText, Standard, Validator}};
fn check_and_fix_accessibility(path: &str) -> anyhow::Result<()> {
let mut doc = PdfDocument::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(())
}Produce ISO 15930-compliant PDF/X-3 and PDF/X-4 files for professional printing. Set output intent, bleed, trim box, and color profiles programmatically.
use pdfluent::{
PdfDocument, Page,
print::{OutputIntent, IccProfile, PdfXLevel, Box as PrintBox},
};
fn create_print_ready_document() -> anyhow::Result<()> {
let mut doc = Document::new();
// Set PDF/X-3 output intent with FOGRA39 CMYK profile
let profile = IccProfile::from_file("FOGRA39L_coated.icc")?;
doc.set_output_intent(OutputIntent::new(PdfXLevel::X3, profile)
.with_output_condition("FOGRA39 (ISO Coated v2 300%)")
.with_registry_name("http://www.color.org")
);
let mut page = Page::new_mm(210.0, 297.0); // A4
// Set 3 mm bleed on all sides
page.set_bleed_box_mm(3.0, 3.0, 3.0, 3.0);
// Set trim box to page boundary
page.set_trim_box_mm(0.0, 0.0, 210.0, 297.0);
doc.add_page(page);
doc.save("output.pdf")?;
Ok(())
}