Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image replacement #2

Open
xamgore opened this issue Sep 26, 2024 · 0 comments
Open

Image replacement #2

xamgore opened this issue Sep 26, 2024 · 0 comments

Comments

@xamgore
Copy link
Owner

xamgore commented Sep 26, 2024

The issue is mostly about the API, as the implementation is quite simple. Either replace the image in the zip archive itself, or replace a placeholder with some XML which encodes the image and its formatting.

Right now it looks like this:

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let path = "./examples/image-replacement/input.docx";
  let mut file = DocxFile::from_path(path)?;

  let path = "./examples/image-replacement/output.docx";
  let mut result = BufWriter::new(File::create(path).unwrap());

  let cat_img = include_bytes!("cat.jpg");
  file.replace_file(&mut result, "word/media/image1.jpg", cat_img)?;
                         ^^^^^^

  Ok(())
}

If I want to replace >1 images, there will be a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant