WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File("C:/Users/aagarwal/Desktop/02_Service_Plan.docx"));
//Identifying JAXB object
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
String xpath = "//w:drawing";
List<Object> list = documentPart.getJAXBNodesViaXPath(xpath, true);
System.out.println(list.size());
//Removing the relationship
MainDocumentPart Part = wordMLPackage.getMainDocumentPart();
RelationshipsPart rp = Part.getRelationshipsPart();
for ( Relationship r : rp.getRelationships().getRelationship() ) {
Part part = rp.getPart(r);
if (part instanceof ImagePngPart) {
rp.removeRelationship(r);
break;
}
}
//removing the JAXB object
list.remove(0);
wordMLPackage.save(new java.io.File("C:/Users/aagarwal/Desktop/02_Service_Plan2.docx"));[img][/img]
<w:sdt>
<w:sdtPr>
<w:id w:val="-172113594"/>
<w:picture/>
</w:sdtPr>
<w:sdtContent>
<w:p w14:paraId="542F0169" w14:textId="4DBB1CD1">
<w:r>
<w:rPr>
<w:noProof/>
</w:rPr>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="1905000" cy="927184"/>
<wp:effectExtent l="0" t="0" r="0" b="6350"/>
<wp:docPr id="2" name="Picture 1"/>
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks noChangeAspect="true"/>
</wp:cNvGraphicFramePr>
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic>
<pic:nvPicPr>
<pic:cNvPr id="0" name="Picture 1"/>
<pic:cNvPicPr>
<a:picLocks noChangeAspect="true" noChangeArrowheads="true"/>
</pic:cNvPicPr>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId8"/>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr bwMode="auto">
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="1905000" cy="927184"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:noFill/>
<a:ln>
<a:noFill/>
</a:ln>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
</w:p>
</w:sdtContent>
</w:sdt>
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File("C:/Users/aagarwal/Desktop/02_Service_Plan.docx"));
//Identifying JAXB object
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
String xpath = "//w:picture";
List<Object> list = documentPart.getJAXBNodesViaXPath(xpath, false);
System.out.println(list.size());
//Removing the relationship
MainDocumentPart Part = wordMLPackage.getMainDocumentPart();
RelationshipsPart rp = Part.getRelationshipsPart();
for ( Relationship r : rp.getRelationships().getRelationship() ) {
Part part = rp.getPart(r);
if (part instanceof ImagePngPart) {
rp.removeRelationship(r);
part.remove();
System.out.println(part.getSourceRelationship().getId());//and it gives rel id= rId8
break;
}
}
//removing the JAXB object
list.remove(0);
wordMLPackage.save(new java.io.File("C:/Users/aagarwal/Desktop/02_Service_Plan2.docx"));
<w:sdt>
<w:sdtPr>
<w:id w:val="-172113594"/>
<w:picture/>
</w:sdtPr>
<w:sdtContent>
<w:p w14:paraId="542F0169" w14:textId="4DBB1CD1">
<w:r>
<w:rPr>
<w:noProof/>
</w:rPr>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="1905000" cy="927184"/>
<wp:effectExtent l="0" t="0" r="0" b="6350"/>
<wp:docPr id="2" name="Picture 1"/>
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks noChangeAspect="true"/>
</wp:cNvGraphicFramePr>
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic>
<pic:nvPicPr>
<pic:cNvPr id="0" name="Picture 1"/>
<pic:cNvPicPr>
<a:picLocks noChangeAspect="true" noChangeArrowheads="true"/>
</pic:cNvPicPr>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId8"/>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr bwMode="auto">
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="1905000" cy="927184"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:noFill/>
<a:ln>
<a:noFill/>
</a:ln>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
</w:p>
</w:sdtContent>
</w:sdt>
E remove(int index) Removes the element at the
specified position in this list (optional operation). Shifts
any subsequent elements to the left (subtracts one
from their indices). Returns the element that was
removed from the list.
Users browsing this forum: Bing [Bot] and 50 guests