Skip to main content

lightweight_pdf_core/
lib.rs

1//! Document model, elements and builder API for `lightweight-pdf`. No font bytes, no
2//! PDF types (`plan/00a-contracts-and-artifacts.md`, point 3) — this crate
3//! knows nothing but the document tree, styling and `FontKey`.
4
5mod currency;
6mod document;
7mod element;
8mod image;
9mod list;
10mod style;
11mod table;
12mod watermark;
13
14pub use currency::*;
15pub use document::*;
16pub use element::*;
17pub use image::*;
18pub use list::*;
19pub use style::*;
20pub use table::*;
21pub use watermark::*;
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn builds_a_minimal_document() {
29        let mut doc = Document::new(PageFormat::A4).margin(Margin::symmetric(20.0, 18.0));
30        doc.add(
31            Row::new()
32                .gap(8.0)
33                .child(Text::new("Rechnung").size(22.0))
34                .child(Text::new("RE-2026-0042")),
35        );
36        assert_eq!(doc.children.len(), 1);
37        match &doc.children[0] {
38            Element::Row(row) => assert_eq!(row.children.len(), 2),
39            _ => panic!("expected Row"),
40        }
41    }
42
43    #[test]
44    fn str_converts_into_text_element() {
45        let el: Element = "Hallo".into();
46        match el {
47            Element::Text(t) => assert_eq!(t.content, "Hallo"),
48            _ => panic!("expected Text"),
49        }
50    }
51}