bokuweb / docx-rs

:memo: A .docx file writer with Rust/WebAssembly.
https://bokuweb.github.io/docx-rs/
MIT License
323 stars 56 forks source link

Open a include images docx file. Then save it. All images disappeared. #717

Open zemelLeong opened 1 month ago

zemelLeong commented 1 month ago

I use this code read this file got the issue.

impl Template {
    pub fn new(path: String) -> errors::Result<Self> {
        let path = PathBuf::from(path);

        let mut buf: Vec<u8> = Vec::new();
        File::open(path)?.read_to_end(&mut buf)?;

        let docx = docx_rs::read_docx(&buf)?;

        Ok(Self { docx })
    }

    pub fn save(self, path: &str) {
        let path = std::path::Path::new(path);
        let file = std::fs::File::create(path).unwrap();

        self.docx.build().pack(file).unwrap();
    }
}

Template::new(path)?.save("./xxx.docx")

screenshot

The 无法显示该图片 means cannot show this image. image