bokuweb / docx-rs

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

`read_docx` does not parse image? #617

Open jymchng opened 1 year ago

jymchng commented 1 year ago

Describe the bug

docx_rs::read_docx reading a .docx file with images should return Docx struct with non-empty RunChild::Drawing variant with Drawing.Pic.image to be a non-empty vector but it doesn't.

Reproduced step

Steps to reproduce the behavior:

fn read_to_vec(file_name: &PathBuf) -> anyhow::Result<Vec<u8>> {
    let mut buf: Vec<u8> = Vec::new();
    std::fs::File::open(file_name)?.read_to_end(&mut buf)?;
    Ok(buf)
}

let mut original_docx = docx_rs::read_docx(&read_to_vec(&path)?)?;
dbg!(&original_docx);

Expected behavior

The dbg!(&original_docx); should print out something that indicates that RunChild::Drawing variant with Drawing.Pic.image is a non-empty vector.

Actual behavior

Instead, it prints out this:

children: [
                                    Drawing(
                                        Drawing {
                                            data: Some(
                                                Pic(
                                                    Pic {
                                                        id: "rId5",
                                                        image: [],
                                                        size: (
                                                            679639,
                                                            679639,
                                                        ),
                                                        position_type: Inline,
                                                        simple_pos: false,
                                                        simple_pos_x: 0,
                                                        simple_pos_y: 0,
                                                        layout_in_cell: true,
                                                        relative_height: 0,
                                                        allow_overlap: true,
                                                        position_h: Offset(
                                                            0,
                                                        ),
                                                        position_v: Offset(
                                                            0,
                                                        ),
                                                        relative_from_h: Margin,
                                                        relative_from_v: Margin,
                                                        dist_t: 0,
                                                        dist_b: 0,
                                                        dist_l: 0,
                                                        dist_r: 0,
                                                        rot: 0,
                                                    },
                                                ),
                                            ),
                                        },
                                    ),
                                ]

This indicates that indeed, the images are not read.

Screenshots

Screenshot of original .docx file image

Desktop (please complete the following information)