File: image_floating.rs

package info (click to toggle)
rust-docx-rs 0.4.18-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,072 kB
  • sloc: xml: 194; makefile: 7
file content (24 lines) | stat: -rw-r--r-- 651 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::fs::*;
use std::io::Read;

use docx_rs::*;

pub fn main() -> Result<(), DocxError> {
    let path = std::path::Path::new("./output/examples/image_floating.docx");
    let file = File::create(path).unwrap();
    let mut img = File::open("./images/cat_min.jpg").unwrap();
    let mut buf = Vec::new();
    let _ = img.read_to_end(&mut buf).unwrap();

    let pic = Pic::new(&buf)
        .size(320 * 9525, 240 * 9525)
        .floating()
        .offset_x(300 * 9525)
        .offset_y(400 * 9525);

    Docx::new()
        .add_paragraph(Paragraph::new().add_run(Run::new().add_image(pic)))
        .build()
        .pack(file)?;
    Ok(())
}