bokuweb / docx-rs

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

Images in headers/footers not importing #608

Closed gjblajian closed 8 months ago

gjblajian commented 1 year ago

Describe the bug

When an image is in the header or footer the image is not present in the JSON of readDocx()

Reproduced step

Steps to reproduce the behavior:

  1. create a document with an image in the header or footer
  2. import that document using readDocx
  3. image is not present

Expected behavior

All images should be referenced in the JSON output of readDocx regardless of position in the document

Actual behavior

Image is not present when it is in the header or footer

Screenshots

N/A

Desktop (please complete the following information)

N/A

gjblajian commented 1 year ago

@bokuweb could you please look into this? Thank you.

bokuweb commented 1 year ago

@gjblajian Sorry for late. I'm busy now... I'll improve it.

arifd commented 1 year ago

Images in headers (and probably footers) are also broken when created programmatically

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!("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(())
}