| |
 |
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
34
35
36
|
<%@ Page language="c#"
AutoEventWireup="false"
CodeBehind="CreateFromTemplate.aspx.cs"
Inherits="Aspose.Slides.WF.Template.CreateFromTemplate"
MasterPageFile="~/tpl/Demo.Master"
Title = "Create Slide from Template - Aspose.Slides Demos"
%>
<asp:Content 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>
|
| C# |
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
102
103
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Aspose.Slides.WF.Template
{
public partial class CreateFromTemplate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, System.EventArgs e)
{
System.IO.FileStream fis = new System.IO.FileStream(MapPath(".") + "\\demo.ppt", System.IO.FileMode.Open, System.IO.FileAccess.Read);
Presentation pres = new Presentation(fis);
fis.Close();
Slides slides = pres.Slides;
for (int i = 0; i < slides.Count; i++)
{
// Set text of standard slide placeholders
Placeholders pholders = slides[i].Placeholders;
for (int j = 0; j < pholders.Count; j++)
{
TextHolder th = pholders[j] as TextHolder;
if (th != null)
{
if (th.Text == "H1")
th.Paragraphs[0].Portions[0].Text = "Demo Presentation";
else if (th.Text == "SH1")
th.Paragraphs[0].Portions[0].Text = "Aspose.Slides.Template";
else if (th.Text == "T1")
{
switch (i)
{
case 1:
th.Paragraphs[0].Portions[0].Text = "With Aspose.Slides you can: Open, read and save Microsoft PowerPoint presentations.";
break;
case 2:
th.Paragraphs[0].Portions[0].Text = "With Aspose.Slides you can: Change standard text placeholders as well as custom text frames.";
break;
case 3:
th.Paragraphs[0].Portions[0].Text = "With Aspose.Slides you can: Replace background pictures with any picture from presentation or new picture.";
break;
}
}
}
}
// Set text for text frames
Shapes shapes = slides[i].Shapes;
for (int j = 0; j < shapes.Count; j++)
{
TextFrame tf = shapes[j].TextFrame;
if (tf != null)
{
if (tf.Text == "CT1")
tf.Paragraphs[0].Portions[0].Text = "Created on:";
else if (tf.Text == "CT2")
tf.Paragraphs[0].Portions[0].Text = System.DateTime.Now.ToShortDateString();
else if (tf.Text == "P1")
{
tf.Paragraphs[0].Portions[0].Text = "Slide " + (i + 1).ToString();
}
}
}
}
pres.Save("demoppt.ppt",Aspose.Slides.Export.SaveFormat.Ppt,Response,false);
this.Response.End();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
|
|
|
|