Hello,
How can I set CTShapeProperties (of DML package) to the image/picture that I am trying to insert in docx using docx4j? Is it even possible to use DML classes while creating docx using docx4j?
Thanks
It is currently Mon Aug 03, 2026 11:32 pm
News of docx4j WordprocessingMLPackage wordprocessingMLPackage = Docx4J.load(new File(System.getProperty("user.dir") + "/uploads/chartCopy.docx"));
Relationship rel = relationshipsPart.getRelationshipByType(Namespaces.SPREADSHEETML_CHART);
Part part = relationshipsPart.getPart(rel);
System.out.println(part.getPartName().getName() );
wordprocessingMLPackage.getMainDocumentPart().addTargetPart(part, RelationshipsPart.AddPartBehaviour.RENAME_IF_NAME_EXISTS);
wordprocessingMLPackage.save(new File(System.getProperty("user.dir") + "/uploads/chartCopyNew.docx"));
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
mainDocumentPart.addStyledParagraphOfText("Title", "Hello World!");
mainDocumentPart.addParagraphOfText("Test");
File exportFile = new File("hello.docx");
wordPackage.save(exportFile);
BinaryPartAbstractImage.createImagePart(wordMLPackage,
headerPart, BufferUtil.getBytesFromInputStream(WordX.class.getResourceAsStream("myimage.png")));Total posts 10234 • Total topics 2888 • Total members 2109