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

Free Support Forum - aspose.com

Converting EMF to PNG

I’m trying to convert an emf picture to png with the following code:

  Workbook book = new Workbook("C:\\Image.xlsx");
  for (Object sheet : book.getWorksheets()) {
      for (Object obj : ((Worksheet)sheet).getShapes()) {
          Shape shape = (Shape)obj;
          if (shape.getMsoDrawingType() == MsoDrawingType.PICTURE) {
              Picture picture = (Picture)shape;
              Image image = Image.load(new ByteArrayInputStream(picture.getData()));
              EmfRasterizationOptions rasterizationOptions = new EmfRasterizationOptions();
              rasterizationOptions.setPageSize(new SizeF(image.getWidth(), image.getHeight()));
              PngOptions options = new PngOptions();
              ByteArrayOutputStream png = new ByteArrayOutputStream();
              image.save(png, options);
  book.save("C:\\Image2.xlsx", SaveFormat.XLSX);

Notice that the output file has borders around the picture.
How do I remove them?

Image.zip (49.5 KB)

Thank you for your query.

Could you please explain the code little bit as I am not able to compile it using the latest version of Aspose.Cells 20.2.x. Which version of the product(s) are you using? Please provide us a sample code where all the classes are fully qualified for our reference. If possible send us a simplified runnable complete project for our testing. We will give it a try and share the feedback.

We have investigated it more and observed that you are using Aspose.Imaging for this conversion. We are investigating this issue and will provide our feedback after detailed analysis.


I have observed the issue shared by you. An issue with ID IMAGINGNET-3774 has been created in our issue tracking system to further investigate and resolve the issue w.r.t Aspose.Imaging. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

The issues you have found earlier (filed as IMAGINGNET-3774) have been fixed in this update.