Accessing pictures in existing powerpoint slides

Hi,

I'm trying to use Aspose Slides.NET to simply combine several .ppt files into a single .ppt file, automatically.

I can get it to open a list of files, and clone all of the slides into a single presentation. I can also copy all of the pictures into this presentation. That's all fine.

I understand that the presentation refers to images by the ID of the image in the Pictures collection. I can not figure out how to access the existing references to pictures in slides that I have not created, in order to update them to their new pictureId in the combined Pictures collection in the new combined presentation. If I iterate through the slide.Shapes collection, none of them seem to be using the FillType.Picture fill type - they are all NoFill.

Could you please provide me with an example of how combine two sets of slides that contain pictures? If I can solve this problem, we will certainly purchase a licence for the product.

Thanks,

Andrew Thompson
Get Started


This message was posted using Aspose.Live 2 Forum

Hi Andrew,

There are two approached to find the exisitng references to the pictures as illustrated by the following example:

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

// Approach one

foreach( Aspose.Slides.Picture pic in pres.Pictures)

{

System.Drawing.Image img = pic.Image;

Response.Write( pic.PictureId + " - " + pic.ImageFormat + "
" );

}

// Approach two

Slide sld = pres.GetSlideByPosition(1);

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

{

if (shp is PictureFrame)

{

PictureFrame pf = (PictureFrame)shp;

Response.Write(pf.PictureId + " - "+ pf.PictureFileName + "
");

}

}

Thanks msabir,



Casting the Shape as a PictureFrame has indeed allowed me to identify which shapes contain pictures within the slides I am cloning.



I then try to increment the PictureId by the number of pictures that already existed before I added the new slide set’s pictures to the presentation.Pictures collection. This is not working. In fact, it seems that this approach will never work, as after I have added two more pictures to the original Pictures collection, the ids of the three pictures are 1, 2 and 2 respectively, i.e. the second and third pictures in the collection have the same ID. This seems strange as the ID seems to be the only way to uniquely identify images within the collection. Is this a bug?



Could you tell me where I’m going wrong, or provide a code sample? I simply need to clone slides from one presentation into an existing presentation, where those slides contain pictures.



Thanks



Andrew

Hi Andrew,

You can clone slides containing pictures from one presentation to the other using Presentation.CloneSlide() method. An example is as under:

Presentation SourcePres = new Presentation("src.ppt");

Presentation TargetPres = new Presentation("target.ppt");

Slide slideToClone=SourcePres.GetSlideByPosition(1);

System.Collections.SortedList sl = new System.Collections.SortedList();

SourcePres.CloneSlide(slideToClone,1,TargetPres,sl);

TargetPres.Write("target.ppt");

Hi Muhammad,



I’m well aware of the CloneSlide() method, hence my references in both of my previous posts to “cloning” slides. My code is extremely similar to the example that you supplied.



My problem is that when I clone a slide from a source presentation into a target presentation, the cloned slides seem to be referencing the pictures from the target presentation, NOT the pictures they originally referenced in the source presentation. For example, if both presentations only had one picture in them, and one reference to it, when cloned, the cloned slide is using the picture from the target presentation instead of the picture that it used to use in the source presentation. I believe this is due to them referring to pictures from the Pictures collection by ID, so for example they are both referring to picture with PictureId 1, which is the picture that always had PictureId 1 in the target presentation.



Can you confirm this behaviour? Or is the CloneSlide method supposed to also copy the picture data from the source presentation and add it to the target presentation’s Picture collection, and update the references automatically? If so, then it does not appear to be functioning correctly.



I have attached my source code, which you will probably not be able to test directly as it runs within a CMS, however you will be able to see that I am indeed using the CloneSlide method as you suggest.



Thanks



Andrew

Hi Andrew,

Actually this is PowerPoint behavior. As a reverse approach, you can add two same pictures on a slide using MS PowerPoint and check their IDs through Aspose, you will get both of them same. The pictures collection in a presentation is believed to be a set of unique pictures. One picture will be assigned only one id, whether you insert it to slides more than once. So, please check, if you are cloning the same picture to the target presentation where that picture already exists, it will have the same id.

Hi Muhammad,



My problem is certainly not that I am using multiples of the same picture. I have checked this yet again, even though it is not the issue I am trying to solve.



My problem is that when you clone a slide that contains an image from a source presentation into a target presentation, the image from the source slide is not carried over into the target slide.



Could you please tell me if it is possible to clone slides (using the CloneSlide() method or some other method) from one presentation that contains images, into another presentation that contains images, and have the images display correctly as they did in the original presentations?



I have tried the following methods:

A) simply use the CloneSlide() method with four input parameters.

This method resulted in the pictures from the target presentation being displayed in slides that had been imported from the source presentation. I understand this is because it refers to images by their Id within the Pictures collection, and the Id doesn’t change when you clone a slide into another presentation.



B) as above, but also manually iterating through the Pictures collection in the source presentation, and adding these pictures to the Target presentation’s Pictures collection.

This method indeed increased the size of the output file according to what I would expect with all pictures combined into the same file. However the same behaviour was seen with the original target presentation’s images being repeated on slides from the source presentation.



C) as above, but also finding PictureFrame shapes within the newly cloned slides, and manually updating the PictureFrame.PictureId property to attempt to point it to where the imported pictures should now be residing in the Pictures collection (e.g. PictureId += num_existing_pictures).

This method resulted in all images in cloned slides just appearing as boxes with a large red cross in them and an error message.



Could you please advise me on what the correct method is for what I’m trying to do (simply merge multiple presentations with images carrying across properly), or confirm that it is not possible with your product?



Thanks



Andrew



Hi Andrew,

CloneSlide() method should fullfill your requirement. It would be great, if you can provide a sample test case of your problem for investigation?