Page 1 of 1

ImageJpegPart

PostPosted: Tue Nov 29, 2016 7:46 pm
by Olivier
Hi,

I want to put an image in e header. I have used the docx4j webapp to generate the java code of the header. But for the image webapp application suggest to use
Code: Select all
org.docx4j.openpackaging.parts.WordprocessingML.ImageJpegPart


So I have write this:
Code: Select all
File img = new File("logo.jpeg");
      InputStream is = new BufferedInputStream(new FileInputStream(img));
      ImageJpegPart imgJpgPart = new ImageJpegPart(new PartName("/word/media/image1.jpeg"));
      imgJpgPart.setBinaryData(is);
                wordMLPackage.getParts().put(imgJpegPart);


but when I open my document like a ZIP there no image... anyone have a example please?

Thanks a lot

Re: ImageJpegPart

PostPosted: Wed Nov 30, 2016 1:24 pm
by jason
You need to add the image part as a rel of the header part; method addTargetPart does this, and returns a relId

You need to create a suitable XML structure in relevant header. That XML structure includes the relId.

See https://github.com/plutext/docx4j/blob/ ... geAdd.java as an example. BinaryPartAbstractImage helps with the above.

Re: ImageJpegPart

PostPosted: Fri Jan 06, 2017 12:01 am
by Olivier
Thanks a lot for your help