Chart Saved as an Image in Java Looks Different than It Does in PowerPoint

Hello,

I’m trying to extract charts from PowerPoint and save them as images, but the images have many discrepancies - the quality is low, text is sometimes missing, and the style is different. Is there another way to extract the images?

Code:

Presentation presentation = new Presentation("c:\\work\\charts.pptx");
presentation.getSlides().forEach(slide -> {
    slide.getShapes().forEach(shape -> {
        if (shape instanceof Chart chart) {
            chart.getImage().save("c:\\work\\chart"+ Math.random() +".png", ImageFormat.Png);
        }
    });
});

PPT file:
charts.zip (95.0 KB)

Couple of examples (we have found many more):
image.png (51.0 KB)
image.png (115.9 KB)

@dfinsolutions,
Thank you for reporting on the issue. I’ve reproduced the problems with the charts when converting slides from the PowerPoint presentation to images. We are sorry that you encountered these problems.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39625

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@dfinsolutions,
Our developers have investigated the case.

You can improve the quality of your images by using a scale of 3 or 4.

float scaleX = 4;
float scaleY = scaleX;

chart.getImage(ShapeThumbnailBounds.Shape, scaleX, scaleY).save("c:\\work\\chart"+ Math.random() +".png", ImageFormat.Png);

Please try using the ShapeThumbnailBounds.Appearance mode.

chart.getImage(ShapeThumbnailBounds.Appearance, scaleX, scaleY).save("c:\\work\\chart"+ Math.random() +".png", ImageFormat.Png);

Create Shape Thumbnails|Aspose.Slides Documentation

We have logged issues related to unwanted style changes. We will keep you updated.

Hi @andrey.potapov,

Thank you for the response.

Using the scale scaleX/scaleY parameters does improve the quality of the chart images.

ShapeThumbnailBounds.Appearance does help to resolve the text disappearance issues (unwated style changes still exist), but additionally, the converted charts don’t have padding around them (see attached image). With ShapeThumbnailBounds.Shape, padding does exist.

I used the following code:

    Presentation presentation = new Presentation("/Users/user/Downloads/charts.pptx");
    String outputDir = "/Users/user/Downloads/conversion/" + LocalDateTime.now() + "/";
    Files.createDirectories(Paths.get(outputDir));
    presentation.getSlides().forEach(slide -> {
      slide.getShapes().forEach(shape -> {
        if (shape instanceof Chart chart) {
          chart
              .getImage(ShapeThumbnailBounds.Appearance, 4, 4)
              .save(
                  outputDir + Math.random() + ".png",
                  ImageFormat.Png
              );
        }
      });
    });

0.35448207135410126.png (52.4 KB)

@dfinsolutions,
Thank you for the message. Could you please indicate what padding you mean on a screenshot?

@andrey.potapov Sure.

Here’s a chart image with padding (produced with ShapeThumbnailBounds.Shape):
0.6978180190633051.png (74.9 KB)

This one is without padding (produced with ShapeThumbnailBounds.Appearance):
0.35448207135410126.png (52.4 KB)

It can be seen that dimensions and sizes of the images differ too.

@dfinsolutions,
Thank you for the clarification. I’ve forwarded your requirements to our developers.

1 Like

A post was split to a new topic: Font Changes to Some Default Font when Creating an Image of a Chart

Hi, below are the latest updates which I shared with Ethan on Consulting meeting regarding the three sub-issues that are opened:

  1. Missing Bevel Effect on 3D Clustered Column Chart in Generated PNG
    This is a new feature request, and at the moment we don’t have any updates on its implementation.

  2. Incorrect Positioning of Horizontal Axis Labels in Generated PNG
    Our team is actively working on this issue. We have already corrected the legend rendering for the 3D Pie Chart, and efforts to address the remaining concerns are ongoing. The tentative ETA for a fix is 25.4.

  3. Missing Perspective on 3D Clustered Column Chart in Generated PNG
    This task is still under investigation. We are exploring a suitable approach to ensure proper 3D rendering with perspective projection. The tentative ETA for a fix is 25.5.

We appreciate your patience and cooperation.

Best Regards,