use crate::{PdfAError, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PdfALevel {
PdfA1b,
PdfA1a,
PdfA2b,
PdfA2u,
PdfA2a,
PdfA3b,
PdfA3u,
PdfA3a,
}
impl PdfALevel {
#[must_use]
pub const fn part(&self) -> u8 {
match self {
Self::PdfA1b | Self::PdfA1a => 1,
Self::PdfA2b | Self::PdfA2u | Self::PdfA2a => 2,
Self::PdfA3b | Self::PdfA3u | Self::PdfA3a => 3,
}
}
#[must_use]
pub const fn conformance(&self) -> &'static str {
match self {
Self::PdfA1b | Self::PdfA2b | Self::PdfA3b => "B",
Self::PdfA1a | Self::PdfA2a | Self::PdfA3a => "A",
Self::PdfA2u | Self::PdfA3u => "U",
}
}
#[must_use]
pub fn parse_arg(s: &str) -> Option<Self> {
match s.to_lowercase().as_str() {
"1b" | "pdfa1b" | "pdf/a-1b" => Some(Self::PdfA1b),
"1a" | "pdfa1a" | "pdf/a-1a" => Some(Self::PdfA1a),
"2b" | "pdfa2b" | "pdf/a-2b" => Some(Self::PdfA2b),
"2u" | "pdfa2u" | "pdf/a-2u" => Some(Self::PdfA2u),
"2a" | "pdfa2a" | "pdf/a-2a" => Some(Self::PdfA2a),
"3b" | "pdfa3b" | "pdf/a-3b" => Some(Self::PdfA3b),
"3u" | "pdfa3u" | "pdf/a-3u" => Some(Self::PdfA3u),
"3a" | "pdfa3a" | "pdf/a-3a" => Some(Self::PdfA3a),
_ => None,
}
}
}
impl std::fmt::Display for PdfALevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"PDF/A-{}{}",
self.part(),
self.conformance().to_lowercase()
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IssueSeverity {
Error,
Warning,
Info,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IssueCategory {
Fonts,
Color,
Metadata,
Structure,
Actions,
Encryption,
Annotations,
Transparency,
Attachments,
}
#[derive(Debug, Clone)]
pub struct PdfAIssue {
pub severity: IssueSeverity,
pub category: IssueCategory,
pub message: String,
pub clause: Option<String>,
pub page: Option<u32>,
}
#[derive(Debug, Clone)]
pub struct ValidationResult {
pub level: PdfALevel,
pub is_compliant: bool,
pub issues: Vec<PdfAIssue>,
pub error_count: usize,
pub warning_count: usize,
}
impl ValidationResult {
#[must_use]
pub const fn passed(&self) -> bool {
self.error_count == 0
}
}
pub fn validate_pdfa(_pdf_data: &[u8], _level: PdfALevel) -> Result<ValidationResult> {
Err(PdfAError::RequiresLicense.into())
}
#[must_use]
pub const fn generate_pdfa_xmp(
_level: PdfALevel,
_title: Option<&str>,
_author: Option<&str>,
_creator: Option<&str>,
) -> String {
String::new()
}
pub fn add_pdfa_metadata(
_pdf_data: &[u8],
_level: PdfALevel,
_title: Option<&str>,
_author: Option<&str>,
) -> Result<Vec<u8>> {
Err(PdfAError::RequiresLicense.into())
}