Add new shapes in slides using serialization

aspose_seo

Well-known member
Joined
Jan 21, 2007
Messages
294
Programming Experience
1-3
Other than providing different APIs for adding different kind of shapes in slides, Aspose.Slides supports a workaround to add new shapes in slides using Serialization and in this technical tip, we are going to show you how. We will carry out the following steps.

- Create some shape using MS-PowerPoint and save the presentation.
- Read the presentation and its shape using Aspose.Slides.
- Serialize the shape.
- Create a new presentation and add the serialized shape in it.

Code Example

[VB.NET]
'Read the source presentation
Dim srcPres As Presentation = New Presentation("c:\source.ppt")

'Read the shape
Dim srcSld As Slide = srcPres.GetSlideByPosition(1)
Dim srcShape As Shape = srcSld.Shapes(0)

'Serialize the shape
Dim ms As MemoryStream = New MemoryStream()
srcShape.Serialize(ms)

'Create a target presentation
Dim targetPres As Presentation = New Presentation()

'Add a serialized shape inside the target presentation
Dim targetSld As Slide = targetPres.GetSlideByPosition(1)
ms.Position = 0
targetSld.Shapes.Add(ms)

'Write the target presentation on disk
targetPres.Write("c:\target.ppt")
More about Aspose.Slides

- Homepage of Aspose.Slides.
- Read more technical tips by Aspose.Slides.

Contact Information
Suite 119, 272 Victoria Avenue
Chatswood, NSW, 2067
Australia
Aspose - The .NET and Java component publisher
sales@aspose.com
Phone: 888.277.6734
Fax: 866.810.94651
 
Back
Top