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

Free Support Forum - aspose.com

How to convert WMF/EMF to PNG?

Hi ,

I am using Aspose latest version for document conversion. I have attached the sample document with this post. I need to save EMF/WMF image as PNG or JPG format. I tired using following ways, but nothing helps.

Document doc = new Document("input.docx");
NodeList shapes = doc.selectNodes("//Shape");
for (Shape node : shapes)
{
    ImageData image = node.getImageData();
    String name = node.getName();
    writeImageInLocal(".\\temp.png", image.getImageBytes());
}

Need help.

Hi Anbu,

Thanks for your inquiry. The NodeType of wmf file in your document is DrawingML. Please use the following code snippet to achieve your requirements. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "input.docx");
NodeList<DrawingML> shapes = doc.selectNodes("//DrawingML");
for (DrawingML node : shapes)
{
    DrawingMLImageData image = node.getImageData();
    System.out.println(FileFormatUtil.imageTypeToExtension(image.getImageType()));
    image.save(MyDir + "out.png");
}

Hi ,

Thanks for the reply. From your example, i can able to save the WMF image as png. But the converted image is not view-able in any image viewer, browser than MSPaint. Image become corrupted, if i save image as JPG. Am i doing anything wrong?

Hi Anbu,

Thanks for your inquiry. In this case, please use ShapeRenderer.save method to convert the DrawingML/Shape node into specified image type. Please use the following code snippet to achieve your requirements. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");
NodeList<DrawingML> shapes = doc.selectNodes("//DrawingML");
for (DrawingML node : shapes)
{
    node.getShapeRenderer().save(MyDir + "out.png", new ImageSaveOptions(SaveFormat.PNG));
    node.getShapeRenderer().save(MyDir + "out.jpg", new ImageSaveOptions(SaveFormat.JPEG));
}

Hi tahir.manzoor,

Thanks. Like this i tried for other DrawingML, Shapes nodes like ( Shapes, TextBoxes, Chart, SmartArt, Wordart, Equation ) . I have attached document with this post. Is it possible to convert these nodes to images ?? . I hope it is possible as converting this document to html converts all into images. If so please guide me.

Hi Anbu,

Thanks for your inquiry. Yes, you can convert DrawingML/Shapes/GroupShape to image file format. Please use the following code snippet to convert DrawingML/Shapes/GroupShape into images. Hope this helps you.

Please read the features supported of image export from here:
https://docs.aspose.com/words/java/save-in-the-image-jpeg-bmp-png-emf-tiff-svg-format/
https://docs.aspose.com/words/java/drawing-object-features-supported-on-image-export/

int i = 1;
Document doc = new Document(MyDir + "in.docx");
NodeList shapes = doc.selectNodes("//DrawingML");
for (DrawingML node : shapes)
{
    System.out.println("drwaingml");
    node.getShapeRenderer().save(MyDir + "Images\\out" + i + ".png", new ImageSaveOptions(SaveFormat.PNG));
    i++;
}
NodeList shape = doc.selectNodes("//Shape");
for (Shape node : shape)
{
    System.out.println("shape");
    node.getShapeRenderer().save(MyDir + "Images\\out" + i + ".png", new ImageSaveOptions(SaveFormat.PNG));
    i++;
}
NodeList gshape = doc.selectNodes("//GroupShape");
for (GroupShape node : gshape)
{
    System.out.println("GroupShape");
    node.getShapeRenderer().save(MyDir + "Images\\out" + i + ".png", new ImageSaveOptions(SaveFormat.PNG));
    i++;
}

Thanks for the reply. Aspose did great job in rendering Textbox, chart, SmartArt, am much satisfied.

But still a basic DrawingML rectangle shape is not rendered as image. I have attached document with this post.

Hi Anbu,

Thanks for your inquiry. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-8279 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-8279) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.