Box-and-Whisker Chart Gets Squished When Converting a Slide to an Image in C#

Hi Team,

I have a PPTX (attached) with 1 slide. Slide has a Chart of “Box and Whisker” type. When I try to get image of the slide, I see that the chart gets squished to right side.

The code I used:

using Aspose.Slides;
using Aspose.Slides.Export;
using Aspose.Slides.Animation;
using Aspose.Slides.Charts;
using Aspose.Slides.SmartArt;
using Aspose.Slides.Ink;
using System.Drawing;
using System.Drawing.Imaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections;
using System.Xml;
using System.Threading;
using System.Reflection;
using System.IO;
using System.Drawing.Text;
class Program
{
    static void Main(string[] args)
    {
        try
        {
            // Apply Aspose.Slides license
            License license = new License();
            license.SetLicense("Aspose.Total.lic"); // Make sure this file is in your application's directory
            Console.WriteLine("\nLicense applied successfully");

            // Load the presentation
            using (Presentation presentation = new Presentation("sample.pptx"))
            {
                Console.WriteLine("Number of slides in the presentation: " + presentation.Slides.Count);
                
                // Create output directory if it doesn't exist
                string outputDir = "slide_images";
                if (!Directory.Exists(outputDir))
                {
                    Directory.CreateDirectory(outputDir);
                }
                
                // Convert each slide to image
                for (int i = 0; i < presentation.Slides.Count; i++)
                {
                    ISlide slide = presentation.Slides[i];
                    
                    // Create a full scale image
                    using (IImage image = slide.GetImage(1.0f, 1.0f))
                    {
                        string fileName = Path.Combine(outputDir, $"slide_{i + 1}.png");
                        image.Save(fileName, Aspose.Slides.ImageFormat.Png);
                        Console.WriteLine($"Saved slide {i + 1} as {fileName}");
                    }
                }
                
                Console.WriteLine($"\nAll slides exported to images in '{outputDir}' folder");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An error occurred: {ex.Message}");
        }
    }
}

I used Aspose version 25.5. Pls find attached the output image as well.

Could you pls help me resolve this issue ? Thank you,

slide_1.png (17.5 KB)

sample.zip (27.8 KB)

@bhav

It sounds like you’re experiencing an issue with the “Box and Whisker” chart getting squished when converting your PowerPoint slide to an image. This can happen due to the scaling settings used during the image conversion process.

Cause: The squished appearance of the chart is likely due to inappropriate scaling settings or default image size during the conversion.

Solution: Here are a few steps you can take to resolve this issue:

  1. Check the Scale Factor: Ensure that the scale factor you are using in the GetImage method is appropriate. A scale factor of 1.0f might not be sufficient for your chart. Try increasing the scale factor to see if it improves the output.

  2. Use Custom Image Size: Instead of relying on the default size, specify a custom size for the image. This can help maintain the aspect ratio of the chart. For example, you can set a specific width and height when calling GetImage.

    Here’s a code snippet to illustrate this:

    Size imageSize = new Size(1820, 1040); // Adjust the size as needed
    
    using (Presentation presentation = new Presentation("sample.pptx"))
    {
        ISlide slide = presentation.Slides[0];
        using (IImage image = slide.GetImage(imageSize))
        {
            image.Save("slide_1.png", Aspose.Slides.ImageFormat.Png);
        }
    }
    
  3. Update Aspose.Slides Version: Since you are using version 25.5, consider updating to the latest version of Aspose.Slides. There may have been improvements and bug fixes related to chart rendering in newer versions.

  4. Check Chart Properties: Ensure that the chart’s properties are set correctly. Sometimes, adjusting the chart’s layout or size within the PowerPoint file can help prevent it from being squished.

Next Steps: Try these steps and see if they help resolve the issue. If you continue to experience problems, please share more details about the specific behavior you are encountering, and I will be happy to assist you further!

Thank you for your patience, and I look forward to helping you resolve this issue!

@bhav,
Thank you for reporting the issue. I have reproduced the issue of the chart being squished when converting the slide to an image. We apologize for any inconvenience caused.

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): SLIDESNET-45074

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.

The issues you found earlier (filed as SLIDESNET-45074) have been resolved in Aspose.Slides for .NET 25.9 (ZIP, MSI, NuGet, Cross-platform).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.

A post was split to a new topic: Chart Axis Title Is Wrapped Incorrectly When Converting a Slide to an Image