Hi Jason,
When i am trying to add an image to document using docx4j, getting the below exception.
java.io.IOException: Permission denied
Looks like 'createImageInline' method is throwing the exception. The bytes which are passed to addImageToPackage method are correct and the image is of type JPG.
In many of our systems this is working but only in one system we are facing an issue. Could you please let us know what could be the issue.
Using the below code to add image to document.
private void addImageToPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage wordMLPackage, byte[] bytes)
throws Exception {
org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage imagePart = org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage
.createImagePart(wordMLPackage, bytes);
int docPrId = 1;
int cNvPrId = 2;
org.docx4j.dml.wordprocessingDrawing.Inline inline = imagePart.createImageInline("Filename hint",
"Alternative text", docPrId, cNvPrId, false);
org.docx4j.wml.P paragraph = addInlineImageToParagraph(inline);
wordMLPackage.getMainDocumentPart().addObject(paragraph);
}
private org.docx4j.wml.P addInlineImageToParagraph(org.docx4j.dml.wordprocessingDrawing.Inline inline) {
// Now add the in-line image to a paragraph
org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();
org.docx4j.wml.P paragraph = factory.createP();
org.docx4j.wml.R run = factory.createR();
paragraph.getContent().add(run);
org.docx4j.wml.Drawing drawing = factory.createDrawing();
run.getContent().add(drawing);
drawing.getAnchorOrInline().add(inline);
return paragraph;
}