Hi Team,
I have a PPTX (attached) with one slide. When I try to get image of the shape on the slide, I get error from Aspose:
Processing AutoShape 1 on slide 1
Error processing shape on slide 1: Object reference not set to an instance of an object.
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;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Xml;
class Program
{
static void Main(string[] args)
{
try
{
// Note: Running without license (evaluation mode)
Console.WriteLine("Running in evaluation mode");
// Load the presentation
using (Presentation presentation = new Presentation("sample.pptx"))
{
int shapeCounter = 1;
// Loop through all slides
for (int slideIndex = 0; slideIndex < presentation.Slides.Count; slideIndex++)
{
// Get current slide
ISlide slide = presentation.Slides[slideIndex];
// Process each shape in the current slide
foreach (var curShape in slide.Shapes)
{
try
{
IAutoShape? autoShape = curShape as IAutoShape;
if (autoShape != null)
{
Console.WriteLine($"Processing AutoShape {shapeCounter} on slide {slideIndex + 1}");
Aspose.Slides.IImage curImage = autoShape.GetImage(0, 2, 2);
// Save the image with a unique name including slide number
string fileName = $"slide_{slideIndex + 1}_shape_{shapeCounter}.png";
curImage.Save(fileName, Aspose.Slides.ImageFormat.Png);
Console.WriteLine($"Image saved successfully as {fileName}");
shapeCounter++;
}
else
{
Console.WriteLine($"Skipping non-AutoShape on slide {slideIndex + 1}");
}
}
catch (Exception shapeEx)
{
Console.WriteLine($"Error processing shape on slide {slideIndex + 1}: {shapeEx.Message}");
Console.WriteLine($"This may be due to evaluation mode limitations.");
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
I used Aspose version 25.9 and net9.0. Pls fine attached the PPT.
sample.zip (26.0 KB)
Could you pls help me resolve this issue ? Thank you,
Internal reference: CONN-4172657