- Code: Select all
// BinaryPart
BinaryPart binaryPart = new BinaryPart(new PartName("/ppt/media/imagereport.png"));
binaryPart.setBinaryData(bytes);
binaryPart.setContentType(new org.docx4j.openpackaging.contenttype.ContentType(ContentTypes.IMAGE_PNG));
binaryPart.setRelationshipType(Namespaces.IMAGE);
//Relationship bpRelationship = slidePart.addTargetPart(binaryPart);
Pic pic = new Pic();
// nvPicPr
pic.setNvPicPr(new Pic.NvPicPr());
pic.getNvPicPr().setCNvPr(new CTNonVisualDrawingProps());
pic.getNvPicPr().setCNvPicPr(new CTNonVisualPictureProperties());
pic.getNvPicPr().getCNvPicPr().setPicLocks(new CTPictureLocking());
pic.getNvPicPr().setNvPr(new NvPr());
pic.getNvPicPr().getCNvPr().setId(983894378910L);
pic.getNvPicPr().getCNvPr().setName("Report Image");
pic.getNvPicPr().getCNvPr().setDescr("The report");
pic.getNvPicPr().getCNvPicPr().getPicLocks().setNoChangeAspect(true);
pic.setBlipFill(new CTBlipFillProperties());
pic.getBlipFill().setBlip(new CTBlip());
//pic.getBlipFill().getBlip().setEmbed(bpRelationship.getId());
pic.getBlipFill().getBlip().setCstate(STBlipCompression.PRINT);
pic.getBlipFill().setStretch(new CTStretchInfoProperties());
pic.getBlipFill().getStretch().setFillRect(new CTRelativeRect());
pic.setSpPr(new CTShapeProperties());
pic.getSpPr().setXfrm(new CTTransform2D());
pic.getSpPr().getXfrm().setOff(new CTPoint2D());
pic.getSpPr().getXfrm().getOff().setX(0);
pic.getSpPr().getXfrm().getOff().setY(0);
pic.getSpPr().getXfrm().setExt(new CTPositiveSize2D());
pic.getSpPr().getXfrm().getExt().setCx(9144000);
pic.getSpPr().getXfrm().getExt().setCy(6858000);
pic.getSpPr().setPrstGeom(new CTPresetGeometry2D());
pic.getSpPr().getPrstGeom().setPrst(STShapeType.RECT);
pic.getSpPr().getPrstGeom().setAvLst(new CTGeomGuideList());
slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(pic);
The slide I'm adding the image and table too already contains a title and some text which I want to preserve, hence I can't just add a new slide...
I'd be immensely grateful for any help with this.