I am new to this forum and have been using docx4j for manipulating word documents. Recently, I have been have issues inserting image in a table cell (Tc). Here my code.
- Code: Select all
image = BinaryPartAbstractImage.createImagePart(WordprocessingMLPackage.createPackage(), imageByteArray);
CTSdtCell cell = (CTSdtCell)element.getValue();
JAXBElement cellElement = (JAXBElement)cell.getSdtContent().getContent().get(0);
// Get the cell from the CTSdtCell
Tc tableCell = (Tc)cellElement.getValue();
Inline inline = image.createImageInline("", "", 1,2,false);
P imageP = factory.createP();
R imageRun = factory.createR();
imageP.getContent().add(imageRun);
org.docx4j.wml.Drawing drawing = factory.createDrawing();
imageRun.getContent().add(drawing);
drawing.getAnchorOrInline().add(inline);
tableCell.getContent().add(0, imageP);
When I save the document, I don't have any runtime errors. When I open the document, I cannot find the image, but the word shows "The Image currently cannot be displayed". I have trying to fix this issues, but was unable to find any solutions.