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

Free Support Forum - aspose.com

Animarions are getting lost

Hi,


While I am replacing pictures with another picture in a slide, the animation associated with the pictures are getting lost.

The code is as follows:

string output_file_name = string.Empty;
string[] files = System.IO.Directory.GetFiles(fPPTPath);
string fileName = string.Empty;
String PPTFullPath = fPPTPath + “\” + pptname;
Presentation presnew = new Presentation(PPTFullPath);
try
{
Workbook wb = new Workbook();
wb.Open(Excelfile);
wb.CalculateFormula();

XmlDocument xDoc = new XmlDocument();
ArrayList arImage = new ArrayList();
xDoc.Load(fMappingXMLPath);
XmlNodeList xmlimage = xDoc.GetElementsByTagName(“image”);
XmlNodeList xmlImgName = xDoc.GetElementsByTagName(“name”);
int imagecount = 0;

//Read from chartlist.xml file and store images name in Array object
foreach (XmlElement NewImg in xmlImgName)
{
arImage.Add(NewImg.InnerText);
imagecount++;
}
for (int j = 1; j <= presnew.Slides.Count; j++)
{
Slide slide = presnew.GetSlideByPosition(j);
Aspose.Slides.Shapes shapes = slide.Shapes;

for (int i = 0; i < shapes.Count; i++)
{
Aspose.Slides.Shape shape = shapes[i];
//check if the shape is Picture
if (shape is PictureFrame)
{
PictureFrame pic = shape as PictureFrame;
if (pic.AlternativeText == “CustomerName”)
{

}
else if (pic.AlternativeText != “”)
{
for (int k = 0; k < imagecount; k++)
{
string newpic_name = arImage[k].ToString();
//match d alternate text on image wid d image name read from xml file
if (pic.AlternativeText != null && pic.AlternativeText != “” && pic.AlternativeText == newpic_name)
{
//get d absolute path of newpic
string str = fPPTPath + “\” + arImage[k].ToString() + “.jpeg”;
Aspose.Slides.Picture new_pic = new Aspose.Slides.Picture(slide.Parent, str);
int old_pic_id = pic.PictureId,
new_pic_id = slide.Parent.Pictures.Add(new_pic);
pic.PictureId = new_pic_id;
break;
}
}
}
}
}
}


//Save the modified PPT as Output.ppt
output_file_name = fPPTPath + “\” + pptname;
presnew.Write(output_file_name);


Initially the picture had the slide show order and the Animation setting. Those are getting lost. :frowning:
Can you tell me the workaround for that?

Regards,
Dibyendu

Hi Dibyendu,

I have tested the issue pointed by you with a simple test case and animations are not lost. The source ppt(txtbox.ppt) and target ppt(test.ppt) replaced with the new picture having no effect on animations are attached as zip. The code used is as follows.

Presentation pres = new Presentation("d:\\ppt\\animations\\txtbox.ppt");

Slide sld= pres.GetSlideByPosition(1);

foreach (Aspose.Slides.Shape shp in sld.Shapes)

{

if(shp is PictureFrame)

{

PictureFrame pf = (PictureFrame)shp;

Aspose.Slides.Picture pic = new Aspose.Slides.Picture(pres, "d:\\ppt\\animations\\ehan.jpg");

pres.Pictures.Add(pic);

pf.PictureId = pic.PictureId;

}

}

pres.Write("d:\\ppt\\animations\\test.ppt");