File: image_in_header.rs

package info (click to toggle)
rust-docx-rs 0.4.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,124 kB
  • sloc: xml: 194; makefile: 7
file content (16 lines) | stat: -rw-r--r-- 576 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use docx_rs::{Docx, Header, Paragraph, Pic, Run};
use std::{error::Error, io::Cursor};

fn main() -> Result<(), Box<dyn Error>> {
    let cat = Pic::new(include_bytes!("../../images/cat_min.jpg"));
    let header =
        Header::new().add_paragraph(Paragraph::new().add_run(Run::new().add_image(cat.clone())));
    let mut out = Vec::new();
    let docx = Docx::new()
        .header(header)
        .add_paragraph(Paragraph::new().add_run(Run::new().add_image(cat)));
    docx.build().pack(Cursor::new(&mut out))?;

    std::fs::write("/tmp/out.docx", &out)?;
    Ok(())
}