We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Extract wmf-visio drawing from document

Hi Team,

I am able extract the jpeg, png images using the following code. I am not able to extract the wmf ,visio drawing,chem draw images using shapes.

NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : (Iterable) shapes) {
			if (shape.hasImage() && shape.getParentParagraph().getNextSibling() != null
					&& shape.getParentParagraph().getPreviousSibling().getNodeType() == NodeType.SHAPE) {
				
			if (shape.getParentParagraph().getNextSibling().toString(SaveFormat.TEXT).startsWith("Fig"){</div><div><div>ArrayList nodes = extractContent(shape.getParentParagraph(), shape.getParentParagraph(), true);</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>filename = folder_name + "Fig" + i + "_" + name + ".docx";</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>generateDocument(doc, nodes).save(filename);</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>Paragraph fig = (Paragraph) shape.getParentParagraph().getNextSibling();</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>/**</div><div><span class="Apple-tab-span" style="white-space:pre">						</span> * REMOVAL OF NODE(START,END) FROM SOURCE WORD DOC START</div><div><span class="Apple-tab-span" style="white-space:pre">						</span> **/</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>shape.getParentParagraph().insertBefore(new BookmarkStart(doc, "Image_" + i), shape);</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>fig.appendChild(new BookmarkEnd(doc, "Image_" + i));</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>i++;</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>for (Bookmark bookmark : doc.getRange().getBookmarks()) {</div><div><span class="Apple-tab-span" style="white-space:pre">							</span>if (bookmark.getName().startsWith("Image_")) {</div><div><span class="Apple-tab-span" style="white-space:pre">								</span>bookmark.setText("");</div><div><span class="Apple-tab-span" style="white-space:pre">							</span>}</div><div><span class="Apple-tab-span" style="white-space:pre">						</span>}</div></div><div>Thanks in advance,</div><div>kind regards</div><div>Priyanga G </div>

Hi there,


Thanks for your inquiry. Please check following code snippet to extract OLE Objects, hopefully it will help you to accomplish the task.

Document doc = new Document(“test+(14).docx”);<o:p></o:p>

int i = 0;

// Get collection of shapes

NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);

System.out.println("No. of Shapes:" + shapes.getCount());

// Loop through all shapes

for (Shape shape : shapes) {

// Save OleObjects

if (shape.getOleFormat() != null) {

System.out.println(shape);

shape.getOleFormat().save(

"out_" + i++

+ shape.getOleFormat().getSuggestedExtension());

}

}


Best Regards,