| |
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<%@ Page Language="vb" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="Merge-Presentations.aspx.vb" Inherits="Merge_Presentations.Merge_Presentations" Title="Merging Presentations" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table width="90%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td height="41" valign="top">
<img src="/Common/images/heading_lft.jpg" width="19" height="41" /></td>
<td width="100%" class="demos-heading-bg">
<h2 class="demos-heading-bg">
Presentations Merging Demo - Aspose.Slides for .NET</h2>
</td>
<td valign="top">
<img src="/Common/images/heading_rt.jpg" width="19" height="41" /></td>
</tr>
</table>
<p class="componentDescriptionTxt">
The sample demo merges two presentations by using <strong> Slides Cloning</strong> feature of Aspose.Slides for .NET. Click <strong>Browse</strong> buttons to select the
two PowerPoint 97-2003 format presentations (PPT) and then click <strong>Download Merged Presentation</strong> button to download the locked
Presentation created by merging the provided presentations.
</p>
<p>
<asp:Label ID="lblErr" runat="server" Font-Bold="True" ForeColor="Red" Text="Label"
Visible="False"></asp:Label> </p>
<asp:Label ID="Label1" runat="server" Text="Enter First Presentation"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Label ID="Label2" runat="server" Text="Enter Second Presentation"></asp:Label>
<asp:FileUpload ID="FileUpload2" runat="server" /><br />
<br />
<asp:Button ID="btn_Download" runat="server" OnClick="btn_Download_Click" Text="Dwonload Merged Presentation" />
</asp:Content>
|
| Visual Basic |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Aspose.Slides
Imports Aspose.Slides.Export
Namespace Merge_Presentations
Partial Public Class Merge_Presentations
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub btn_Download_Click(ByVal sender As Object, ByVal e As EventArgs)
If Me.FileUpload1.HasFile AndAlso Me.FileUpload2.HasFile Then
Me.lblErr.Visible = False
Try
'Upload first presentation
Dim strFile1 As String = Me.FileUpload1.FileName.Substring(0, Me.FileUpload1.FileName.Length - 4) + DateTime.Now.ToString("hhmmss") & ".ppt"
Me.FileUpload1.PostedFile.SaveAs(Server.MapPath(strFile1))
'Upload second presentation
Dim strFile2 As String = Me.FileUpload2.FileName.Substring(0, Me.FileUpload2.FileName.Length - 4) + DateTime.Now.ToString("hhmmss") & ".ppt"
Me.FileUpload2.PostedFile.SaveAs(Server.MapPath(strFile2))
'Load the uploaded presentations
Dim srcPres1 As New Presentation(Server.MapPath(strFile1))
Dim srcPres2 As New Presentation(Server.MapPath(strFile2))
'Create a new presentation
Dim targetPres1 As New Presentation()
'Clone first presentation with the newly created presentation
Dim targetPres2 As Presentation = getClonedPres(srcPres1, targetPres1)
'Clone the second presentation with the resulting presentation
Dim mergedPresentation As Presentation = getClonedPres(srcPres2, targetPres2)
'Remove the first default slide of the merged presentation
mergedPresentation.Slides.Remove(mergedPresentation.GetSlideByPosition(1))
'Save the merged presentation to the response stream
mergedPresentation.Save("MergedPres.ppt", SaveFormat.Ppt, Response, False)
Response.End()
Catch ex As Exception
Me.lblErr.Visible = True
Me.lblErr.Text = ex.Message
End Try
End If
End Sub
Public Function getClonedPres(ByVal srcPres As Presentation, ByVal targetPres As Presentation) As Presentation
Dim sl As New SortedList()
For i As Integer = 1 To srcPres.Slides.LastSlidePosition
Dim srcSlide As Slide = srcPres.GetSlideByPosition(i)
srcPres.CloneSlide(srcPres.GetSlideByPosition(i), targetPres.Slides.LastSlidePosition + 1, targetPres, sl)
Dim targetSlide As Slide = Nothing
If srcSlide.Notes IsNot Nothing Then
targetSlide = targetPres.GetSlideByPosition(targetPres.Slides.LastSlidePosition)
targetSlide.AddNotes()
For j As Integer = 0 To srcSlide.Notes.Paragraphs.Count - 1
targetSlide.Notes.Paragraphs.Add(New Paragraph(srcSlide.Notes.Paragraphs(j)))
Next j
targetSlide.Notes.Paragraphs.RemoveAt(0)
End If
Next i
Return targetPres
End Function
End Class
End Namespace
|
|
|
|