aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: ddbf2f7acaa47a7bb919cc0c5d85181a93637a6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use lopdf::{Document, Object};


fn main() {
    let mut doc = Document::load("./f1040.pdf").unwrap();

    for (_, mut obj) in &mut doc.objects {
        match &mut obj {
            Object::Dictionary(ref mut d) => {
                for (k, v) in d.iter_mut() {
                    let key = std::str::from_utf8(k).unwrap();

                    if key == "DA" {
                        let properties = v.as_str_mut().unwrap();

                        let new_properties = std::str::from_utf8(properties)
                            .unwrap()
                            .replace("HelveticaLTStd-Bold", "CourierNewPSMT");

                        *properties = new_properties.into_bytes();
                    }
                }
            },
            _ => (),
        }
    }

    doc.save("./new.pdf").unwrap();
}