use crate::config::PdfConfig;
pub fn build_header_template(config: &PdfConfig) -> String {
if !config.display_header_footer {
return "<span></span>".into();
}
if let Some(ref html) = config.header.custom_html {
return html.clone();
}
let h = &config.header;
let left = h.left.as_deref().unwrap_or("");
let center = h.center.as_deref().unwrap_or("");
let right = h.right.as_deref().unwrap_or("");
if left.is_empty() && center.is_empty() && right.is_empty() {
return "<span></span>".into();
}
let font_size = h.font_size.as_deref().unwrap_or("9px");
let color = h.color.as_deref().unwrap_or("#555");
format!(
r#"<div style="width:100%; font-size:{font_size}; color:{color}; display:flex; justify-content:space-between; align-items:center; padding:4px 0.75in 4px 0.75in; font-family:Helvetica,Arial,sans-serif;">
<span>{left}</span>
<span>{center}</span>
<span>{right}</span>
</div>"#,
font_size = font_size,
color = color,
left = left,
center = center,
right = right,
)
}
pub fn build_footer_template(config: &PdfConfig) -> String {
if !config.display_header_footer {
return "<span></span>".into();
}
if let Some(ref html) = config.footer.custom_html {
return html.clone();
}
let f = &config.footer;
let font_size = f.font_size.as_deref().unwrap_or("8px");
let color = f.color.as_deref().unwrap_or("#555");
let left = f.left.as_deref().unwrap_or("");
let center = f.center.as_deref().unwrap_or("");
let right = f.right.as_deref().unwrap_or("");
if !left.is_empty() || !center.is_empty() || !right.is_empty() {
return format!(
r#"<div style="width:100%; font-size:{font_size}; color:{color}; display:flex; justify-content:space-between; align-items:center; padding:4px 0.75in; font-family:Helvetica,Arial,sans-serif;">
<span>{left}</span>
<span>{center}</span>
<span>{right}</span>
</div>"#,
font_size = font_size,
color = color,
left = left,
center = center,
right = right,
);
}
format!(
r#"<div style="width:100%; font-size:{font_size}; color:{color}; text-align:center; padding:4px 0.75in; font-family:Helvetica,Arial,sans-serif;">
Page <span class="pageNumber"></span> / <span class="totalPages"></span>
</div>"#,
font_size = font_size,
color = color,
)
}