How to read Master slide background?

Hi,

we are trying to use Aspose.Slides in our .NET application, we need to export the image of the background for each slide.

Reading this document we are able to recover images of slide background, but only if the background is set on page, if the slide uses a master slide with background we cannot find the image (and we cannot check if slide has a background…).

Reading a slide with background defined in Master slide, we have (using the code of your document):

sl.Background.FillFormat.FillType == FillType.NotDefined
sl.LayoutSlide.Background.FillFormat.FillType == FillType.NotDefined

How can we extract the image used in master slide as background?

Thanks,
Gabriele

Hi Gabriele,

I have observed your requirement and request you to please try using the following sample code on your end to access or extract the slide background. The background can be applied on slide level, layout slide level and Master slide level. You need to verify on all levels, where you are able to access the image associated with background. The following code will help you further in this regard.

public static void testBackgroundExtract()
{

String path = @“D:\Aspose Data”;
//Accessing the presentation
Presentation pres = new Presentation(path + “TestExtraction.pptx”);
Aspose.Slides.IPPImage img = null;
Aspose.Slides.IPPImage Backimg = null;

int slideIndex = 0;
String ImageType = “”;
bool ifImageFound = false;
for (int i = 0; i < pres.Slides.Count; i++)
{

slideIndex++;
//Accessing the first slide
ISlide sl = pres.Slides[i];
System.Drawing.Imaging.ImageFormat Format = System.Drawing.Imaging.ImageFormat.Jpeg;

//Accessing the first slide Slide sl = pres.getSlideByPosition(i);
if (sl.Background.FillFormat.FillType == FillType.Picture)
{
//Getting the back picture
Backimg = sl.Background.FillFormat.PictureFillFormat.Picture.Image;

//Setting the desired picture format

ImageType = Backimg.ContentType;
ImageType = ImageType.Remove(0, ImageType.IndexOf("/") + 1);
Format = GetImageFormat(ImageType);

String ImagePath = path + “BackImage_”;
Backimg.SystemImage.Save(ImagePath + “Slide_” + slideIndex.ToString() + “.” + ImageType, Format);

}
else
{
if (sl.LayoutSlide.Background.FillFormat.FillType == FillType.Picture)
{
//Getting the back picture
Backimg = sl.LayoutSlide.Background.FillFormat.PictureFillFormat.Picture.Image;

//Setting the desired picture format

ImageType = Backimg.ContentType;
ImageType = ImageType.Remove(0, ImageType.IndexOf("/") + 1);
Format = GetImageFormat(ImageType);

String ImagePath = path + “BackImage_Slide_” + i;
Backimg.SystemImage.Save(ImagePath + “LayoutSlide_” + slideIndex.ToString() + “.” + ImageType, Format);

}
else
{
//Getting the back picture
Backimg = sl.LayoutSlide.MasterSlide.Background.FillFormat.PictureFillFormat.Picture.Image;

//Setting the desired picture format

ImageType = Backimg.ContentType;
ImageType = ImageType.Remove(0, ImageType.IndexOf("/") + 1);
Format = GetImageFormat(ImageType);

String ImagePath = path + “BackImage_Slide_” + i;
Backimg.SystemImage.Save(ImagePath + “MasterSlide_” + slideIndex.ToString() + “.” + ImageType, Format);

}
}
}

}

Many Thanks,
Perfect!
With your help we have solved!

Thanks.

Regards,
Gabriele

Hi Gabriele.


You are always welcome. Please share if I may be of further help to you.

Many Thanks,