Skip to main content

Watermark

Struct Watermark 

Source
pub struct Watermark {
    pub text: String,
    pub rotation_deg: f32,
    pub size: f32,
    pub color: Color,
    pub font: FontKey,
}

Fields§

§text: String§rotation_deg: f32

Counter-clockwise rotation in degrees, applied around the body box’s center. 45° (bottom-left to top-right diagonal) matches the conventional “ENTWURF”/“DRAFT” stamp look.

§size: f32§color: Color§font: FontKey

Implementations§

Source§

impl Watermark

Source

pub fn new(text: impl Into<String>) -> Watermark

Examples found in repository?
examples/report.rs (line 23)
10fn main() {
11    let mut doc = Document::new(PageFormat::A4)
12        .margin(Margin::symmetric(56.0, 56.0))
13        .header(Header::new(20.0, |_ctx| {
14            Text::new("Jahresbericht 2026 \u{2014} Muster GmbH").size(9.0).into()
15        }))
16        .header_visible_from(2)
17        .footer(Footer::new(20.0, |ctx| {
18            Text::new(format!("Seite {} von {}", ctx.page, ctx.total_pages))
19                .size(9.0)
20                .align(Align::Center)
21                .into()
22        }))
23        .watermark(Watermark::new("ENTWURF"));
24
25    // --- cover page -----------------------------------------------------
26    doc.add(Spacer::new(220.0));
27    doc.add(Text::new("Jahresbericht 2026").heading1().align(Align::Center));
28    doc.add(Spacer::new(8.0));
29    doc.add(Text::new("Muster GmbH").align(Align::Center));
30    doc.add(Text::new("vorgelegt am 20. August 2026").align(Align::Center));
31    doc.add(Element::PageBreak);
32
33    // --- content ---------------------------------------------------------
34    doc.add(Text::new("1. Zusammenfassung").heading1());
35    doc.add(Text::new(
36        "Das Geschäftsjahr 2026 war geprägt von stabilem Wachstum in allen \
37         Kernbereichen. Die folgenden Abschnitte fassen die wichtigsten \
38         Kennzahlen und Entwicklungen zusammen.",
39    ));
40    doc.add(Spacer::new(12.0));
41
42    doc.add(Text::new("2. Wichtigste Ereignisse").heading2());
43    doc.add(
44        List::new()
45            .bullet(Text::new("Markteinführung des neuen Produkts im zweiten Quartal"))
46            .bullet(Text::new("Erweiterung des Teams um 12 neue Mitarbeitende"))
47            .bullet(Text::new("Eröffnung eines zweiten Standorts")),
48    );
49    doc.add(Spacer::new(12.0));
50
51    doc.add(Text::new("3. Zeitplan").heading2());
52    doc.add(
53        List::new()
54            .numbered(Text::new("Kickoff und Planung (Januar \u{2013} Februar)"))
55            .numbered(Text::new("Umsetzung Phase 1 (M\u{e4}rz \u{2013} Juni)"))
56            .numbered(Text::new("Umsetzung Phase 2 (Juli \u{2013} Oktober)"))
57            .numbered(Text::new("Abschluss und Auswertung (November \u{2013} Dezember)")),
58    );
59    doc.add(Spacer::new(12.0));
60
61    doc.add(Text::new("3.1 Details").heading3());
62    doc.add(Text::new(
63        "Weitere Details zu den einzelnen Phasen finden sich im Anhang. \
64         Diese Überschrift bleibt dank keep_with_next garantiert mit \
65         diesem Absatz auf derselben Seite zusammen.",
66    ));
67
68    let bytes = doc.render().expect("render should succeed");
69    std::fs::write("report.pdf", &bytes).expect("write report.pdf");
70    println!("wrote report.pdf ({} bytes)", bytes.len());
71}
Source

pub fn rotation(self, degrees: f32) -> Watermark

Source

pub fn size(self, size: f32) -> Watermark

Source

pub fn color(self, color: Color) -> Watermark

Trait Implementations§

Source§

impl Clone for Watermark

Source§

fn clone(&self) -> Watermark

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Watermark

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.