J-F-Liu / lopdf

A Rust library for PDF document manipulation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changing the font color

LegendarySaiyan opened this issue · comments

Can you please explain with the examples, how to change the font color?

Tried to do something like this, but didn't work:

    let color_stream = Stream::new(dictionary!{}, vec![
        (color.0).into(),
        (color.1).into(),
        (color.2).into(),
    ]);

    let color_object = Object::Stream(color_stream);
    let color_id = template_pdf.add_object(color_object);

    let content = Content {
        operations: vec![
            Operation::new("BT", vec![]),
            Operation::new("Tf", vec!["F1".into(), font_size.into()]),
            Operation::new("rg", vec![color_id.into()]),
            Operation::new("Td", vec![position.0.into(), position.1.into()]),
            Operation::new("Tj", vec![Object::string_literal(text)]),
            Operation::new("ET", vec![]),
        ],
    };

Oh, i finally got it:

let color = (0, 0, 0);

let color_string = format!("{} {} {} rg", color.0, color.1, color.2);

operations.push(Operation::new(&color_string, vec![]));