Free Support Forum -

Serialization of Slides

Good Afternoon.

I am evaluating your product to use in a slide management site for a client. I would like to be able to save a slide independent of the presentation. I would then like to save the slide to a database. I can then use it to mix and match slides to create custom presentations by deserializing the slide into the presentation. When I tried to use binary serialization it was not possible as the class is not marked as Serializable. I then tried xml serialization but was unable there also as there is no public constructor.

My question is this. Do you not want to allow this functionality by design or is there a dependency in the presentation containing the slide that makes this impossible?

Thanks for your time

Hi Geoff,

Thanks for inquiring Aspose.Slides.

I have observed the requirement shared by you and will try to share both workaround and reason with you. Actually, the slide is not an only entity inside the presentation document object model. Every slide has some master or layout slide associated with it. Also, if there are any images added in the slides they are actually added in presentation image collection but referred in the slide only. So a slide cannot be treated as a separate entity as it does not have the complete picture inside it. But it is one of the important part of the whole picture. I hope this will elaborate the concept before you. So, if you want to serialize, you can save the entire presentation instead of single slide as presentation involves every thing inside it.

Now, coming to solution that I can offer you to get things going on your end. You have requirement of serializing independent slide in database. Aspose.Slides offers the solution of slide cloning or copying. You can use Aspose.Slides to access the every single slide of source presentation copy that independently in some temporary PresentationEx object and then saving the single slide presentation in memory stream. Then converting that memory stream to byte array and populating that to database along with file extension in separate field for future retrieval of the byte array. When you will need to access that slide added in database, you will have to load the byte array and convert that to memory stream. Then load the memory stream back in to PresentationEx. I hope this will help. I have shared the sample code for exporting individual slide to Memory Stream for your kind reference.

public static void changetoMemStream()
PresentationEx origPres = new PresentationEx(“SamplePres.pptx”);

PresentationEx tempPres = null;

foreach (SlideEx slide in origPres.Slides)
tempPres = new PresentationEx();
MemoryStream mem = new MemoryStream();
tempPres.Save(mem , Aspose.Slides.Export.SaveFormat.Pptx);
byte[] buffer = new byte[mem.Length];
mem.Write(buffer, 0, (int)mem.Length);

Please also visit this documentation link for more insight on slide cloning feature that you will be needing when copying slides to and from presentation. Please share, if I may help you further in this regard.

Many Thanks,

Good Morning Mudassir

Thanks for your quick reply. Your solution would definitely work, I had it as a workaround option. Not sure saving to a temp presentation to simply clone slides into a second exact presentation to add to the database makes any practical sense. This would mean loading every presentation and all slides to display to a user to allow them to pick and choose slides.

I was thinking of simply taking each slide in presentation, getting a thumbnail, extract notes, save that to database along with a link to a one slide presentation. So in effect the UI simply shows the thumbnail for the user to build their custom presentation and when they save to allow it to be downloaded I can go and get the 15-20 one slide presentations and merge them all together. I am not sure the implication of master slides are in that scenario. Could you confirm that this actually doable in a performant non killing server way? I don't want to waste time trying this if it will take 40 minutes to create a 20 slide presentation and run my server at 100% for the same 40 minutes. I don't expect you to commit to anything but you know the product better than me so educated guess is all I need to start on a POC.

I have looked at the openxml sdk 2.5 and I assume I will have the same issue with slides referencing data outside the slide xml in that scenario also. Would this be a correct assumption?

Thanks Again

Hi Geoff,

Thanks for sharing the further information.

I like to share that earlier you shared that you need save the individual slide to presentation. So, I shared the solution that worked in that particular scenario.

With some more information shared from you what I have perceived is that you actually wish to show the available slides graphically in some user interface (UI). The user will select the list of slides in UI and on back end the presentation will be generated with selected slides in UI. I hope that I am getting your requirement right up till here.

I like to share that Aspose.Slides manages presentations programatically and there is no front end associated with it. The only way available to depict slides in UI is by generating thumbnails and maintaining some link of thumbnails with slides on back end for references and further implementation of your logic. The implementation plan shared by you in second part of your query is exactly doable and is in fact the only possible solution in your’s mentioned application type.

In the scenario mentioned, you may also not need to even keep the slides as separate entities in databases and saving them as byte array there as it would cost your performance. The better would be to use the presentations stored on your disk and you devise some mechanism on back end that the particular thumbnail selected in UI from user is actually belonging to which presentation and what slide index. With this information available, you would simply clone that slide to your target presentation for the user. Now, coming to your concern about the master slides associated with slides when they are clone. Actually, whenever the slide is cloned using a default clone method, it gets cloned in target presentation with its master and layout slides. This is logical as you need to see exactly the same slide what you have in source presentation. Aspose.Slides also offers you to change the master applied on the slide and apply any template master on cloned slides. If you change the master of any cloned slide in target presentation there is also a provision to delete unused master slides as well inside target presentation to avoid growing presentation size.

I have already shared the documentation link for managing different options available in Slide cloning in my previous post and you can explore them on your end. I also like to add that slide cloning does not take that much time it is efficient process. I also like to share that on normal server, creating a 20 slide presentation wont take that much time. The CPU touching 100% depends upon the server type used on your end and I may not be able to quantify this for you unless you test this in your environment. Also the web server or other server settings may also take part in it. As per my personal experience on my laptop, cloning of 20 slides complete about in minuet or so. But this also depends upon the contents of slides. If there is heavy multimedia content on slide in the form of video, audio and big images. They certainly play their role.

I am sorry, I may not help you OpenXML SDK inquiry. Please share, if I may help you further in this regard.

Many Thanks,

Hi Mudassir,

Yea I would not stream any binary data to the database unless I need to scale the front end, which for now is not the case. My question on overhead was more the issue of opening 20 very small pptx files and extracting the slide. If you think this is something that is quite light weight then I will go ahead with that solution it is pretty good. As for the rest I understand that the performance will greatly vary depending on files sizes, complexity and all that so no worries there. Was just asking in regards to simple benchmarks of the overhead of opening files which can be cumbersome.

Thanks for your input, I will be implementing this. Might be an interesting github project, would anyone be interesting in me sharing this code?

Thanks again

Hi Geoff,

That will be really appreciable if you may please share the sample github project link in this thread as this might be helpful for any other worthy customer in future. I will also appreciate, if you may please also share the feedback in terms of results along side as well in this thread for reference.

Many Thanks,

Hi Mudassir

Will do, stay tuned.