Animarions are getting lost

Last post 10-22-2009, 11:22 PM by msabir. 1 replies.
Sort Posts: Previous Next
  •  10-22-2009, 7:21 AM 203633

    Animarions are getting lost .NET

    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. :( 
    Can you tell me the workaround for that?

    Regards,
    Dibyendu
    Filed under: .NET;Animation;Image;PPT
     
  •  10-22-2009, 11:22 PM 203745 in reply to 203633

    Re: Animarions are getting lost

    Attachment: Present (inaccessible)

    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");


    Muhammad Sabir
    Support Assistant Manager
    Aspose Sialkot Team
    http://www.aspose.com
    Aspose - Your File Format Experts

    Keep in touch! We're on Twitter and Facebook
     
View as RSS news feed in XML