| |
 |
Create Presentation from Template - Aspose.Slides
|
 |
The sample demo reads presentation file, fills some fields with custom data and
streams the resulting file to the client browser.
It reads a demo.ppt and creates a presentation object from it,
then iterates all the slides one by one and finds the text to be updated and replaces
it with new text.
For example, it finds "H1" and replaces it with "Demo Presentation"
| 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
33
|
<%@ Page Language="VB" AutoEventWireup="false" Codebehind="CreateFromTemplate.aspx.vb"
Inherits="Aspose.Slides.WFVB.Template.CreateFromTemplate" MasterPageFile="~/tpl/Demo.Master"
Title="Create Slide from Template - Aspose.Slides Demos" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
<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">
Create Presentation from Template - Aspose.Slides</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 reads presentation file, fills some fields with custom data and
streams the resulting file to the client browser. </p>
<p class="componentDescriptionTxt">
It reads a <strong>demo.ppt</strong> and creates a presentation object from it,
then iterates all the slides one by one and finds the text to be updated and replaces
it with new text.
</p>
<p class="componentDescriptionTxt">
For example, it finds <strong>"H1"</strong> and replaces it with <strong>"Demo Presentation"
</strong>
</p>
<br />
<asp:Button ID="Button1" runat="server" Text="Click here to create a 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
'/////////////////////////////////////////////////////////////////////////
'/ Copyright 2002-2006 Aspose Pty Ltd. All Rights Reserved.
'/
'/ This file is part of Aspose.Project. The source code in this file
'/ is only intended as a supplement to the documentation, and is provided
'/ "as is", without warranty of any kind, either expressed or implied.
'/////////////////////////////////////////////////////////////////////////
Public Class CreateFromTemplate
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fis As System.IO.FileStream = New System.IO.FileStream(MapPath(".") + "\\demo.ppt", System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim pres As Presentation = New Presentation(fis)
fis.Close()
Dim slides As Slides = pres.Slides
Dim i As Integer
For i = 0 To slides.Count - 1
' Set text of standard slide placeholders
Dim pholders As Placeholders = slides(i).Placeholders
Dim j As Integer
For j = 0 To pholders.Count - 1
Dim th As TextHolder
If TypeOf pholders(j) Is TextHolder Then
th = CType(pholders(j), TextHolder)
Else
th = Nothing
End If
If Not th Is Nothing Then
If th.Text = "H1" Then
th.Paragraphs(0).Portions(0).Text = "Demo Presentation"
ElseIf th.Text = "SH1" Then
th.Paragraphs(0).Portions(0).Text = "Aspose.Slides.Template"
ElseIf th.Text = "T1" Then
Select Case i
Case 1
th.Paragraphs(0).Portions(0).Text = "With Aspose.Slides you can: Open, read and save Microsoft PowerPoint presentations."
Exit For
Case 2
th.Paragraphs(0).Portions(0).Text = "With Aspose.Slides you can: Change standard text placeholders as well as custom text frames."
Exit For
Case 3
th.Paragraphs(0).Portions(0).Text = "With Aspose.Slides you can: Replace background pictures with any picture from presentation or new picture."
Exit For
End Select
End If
End If
Next
' Set text for text frames
Dim shapes As Shapes = slides(i).Shapes
For j = 0 To shapes.Count - 1
Dim tf As TextFrame
tf = shapes(j).TextFrame
If Not tf Is Nothing Then
If tf.Text = "CT1" Then
tf.Paragraphs(0).Portions(0).Text = "Created on:"
ElseIf tf.Text = "CT2" Then
tf.Paragraphs(0).Portions(0).Text = System.DateTime.Now.ToShortDateString()
ElseIf tf.Text = "P1" Then
tf.Paragraphs(0).Portions(0).Text = "Slide " + (i + 1).ToString()
End If
End If
Next
Next
'Me.Response.ContentType = "application/vnd.ms-powerpoint"
'Me.Response.AppendHeader("Content-Disposition", "attachment; filename=demoppt.ppt")
'Me.Response.Flush()
'Dim st As System.IO.Stream = Me.Response.OutputStream
'
' Write the file
'
'pres.Write(st)
pres.Save("demoppt.ppt", Export.SaveFormat.Ppt, Response, False)
Me.Response.End()
End Sub
End Class
|
|
|
|