Skip to content

Commit 6268271

Browse files
committed
Inline CSS example added
1 parent a93e57c commit 6268271

File tree

4 files changed

+169
-22
lines changed

4 files changed

+169
-22
lines changed

Aspose.Slides.WebExtensions/PresentationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private static void AddMultiPageOutputFiles(this WebDocument document, string ou
195195
}
196196
}
197197

198-
private static void AddImagesOutput(this WebDocument document, string outputPath, Presentation pres)
198+
public static void AddImagesOutput(this WebDocument document, string outputPath, Presentation pres)
199199
{
200200
for (int index = 0; index < pres.Images.Count; index++)
201201
{
@@ -230,7 +230,7 @@ public static void AddThumbnailsOutput(this WebDocument document, string outputP
230230
}
231231

232232

233-
private static void AddShapeAsImagesOutput<T>(this WebDocument document, string outputPath, Presentation pres)
233+
public static void AddShapeAsImagesOutput<T>(this WebDocument document, string outputPath, Presentation pres)
234234
{
235235
List<T> shapes = ShapeHelper.GetListOfShapes<T>(pres);
236236

Examples/SinglePageApp/Program.cs

Lines changed: 103 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.IO;
33
using Aspose.Slides;
4+
using Aspose.Slides.Charts;
45
using Aspose.Slides.Export.Web;
6+
using Aspose.Slides.SmartArt;
57
using Aspose.Slides.WebExtensions;
68

79
namespace SinglePageApp
@@ -10,7 +12,10 @@ class Program
1012
{
1113
static void Main(string[] args)
1214
{
13-
ExportDefault();
15+
//ExportDefault();
16+
17+
new License().SetLicense(@"c:\bin\aspose\git\slides-net\src\test\bin\Debug\Aspose.Total.Product.Family.lic");
18+
ExportHelloWorldWithInlineCss();
1419

1520
Console.WriteLine("HTML export is complete...");
1621
}
@@ -90,6 +95,32 @@ static void ExportHelloWorldWithStyles()
9095
}
9196
}
9297

98+
static void ExportHelloWorldWithInlineCss()
99+
{
100+
using (Presentation pres = new Presentation("demo.pptx"))
101+
{
102+
WebDocumentOptions options = new WebDocumentOptions { TemplateEngine = new RazorTemplateEngine(), OutputSaver = new FileOutputSaver() };
103+
WebDocument document = new WebDocument(options);
104+
105+
const string templatesPath = "templates\\single-page";
106+
const string outputPath = "inline-css";
107+
108+
// setup global document values
109+
SetupGlobals(document, options, outputPath);
110+
111+
document.Input.AddTemplate<Presentation>("index", @"custom-templates\index-inline-css.html");
112+
113+
AddCommonStylesTemplates(document, templatesPath);
114+
AddCommonShapeTemplates(document, templatesPath);
115+
116+
AddSinglePageCommonOutput(pres, document, outputPath);
117+
AddResourcesOutput(pres, document, options.EmbedImages);
118+
AddScriptsOutput(document, templatesPath);
119+
120+
document.Save();
121+
}
122+
}
123+
93124
static void ExportCustomTableStyles()
94125
{
95126
using (Presentation pres = new Presentation("table.pptx"))
@@ -106,17 +137,10 @@ static void ExportCustomTableStyles()
106137

107138
// setup global document values
108139
WebDocument document = new WebDocument(options);
109-
PresentationExtensions.SetGlobals(document, options, outputPath);
110-
string slidesPath = Path.Combine(outputPath, "slides");
111-
string stylesPath = Path.Combine(outputPath, "styles");
112-
string scriptsPath = Path.Combine(outputPath, "scripts");
113-
114-
document.Global.Put("slidesPath", slidesPath);
115-
document.Global.Put("stylesPath", stylesPath);
116-
document.Global.Put("scriptsPath", scriptsPath);
140+
SetupGlobals(document, options, outputPath);
117141

118142
// add common structure (except table template)
119-
ExportCustomTableStyles_AddCommonStructure(pres, document, templatesPath, outputPath);
143+
ExportCustomTableStyles_AddCommonStructure(pres, document, templatesPath, outputPath, options.EmbedImages);
120144

121145
// add custom table template
122146
document.Input.AddTemplate<Table>("table", @"custom-templates\table-custom-style.html");
@@ -132,38 +156,97 @@ static void ExportCustomTableStyles()
132156
}
133157
}
134158

135-
private static void ExportCustomTableStyles_AddCommonStructure(Presentation pres, WebDocument document,
136-
string templatesPath, string outputPath)
159+
private static void ExportCustomTableStyles_AddCommonStructure(
160+
Presentation pres,
161+
WebDocument document,
162+
string templatesPath,
163+
string outputPath,
164+
bool embedImages)
137165
{
138-
string stylesPath = document.Global.Get<string>("stylesPath");
139-
string scriptsPath = document.Global.Get<string>("scriptsPath");
166+
AddCommonStylesTemplates(document, templatesPath);
167+
168+
document.Input.AddTemplate<Slide>("slide", Path.Combine(templatesPath, "slide.html"));
169+
document.Input.AddTemplate<AutoShape>("autoshape", Path.Combine(templatesPath, "autoshape.html"));
170+
document.Input.AddTemplate<TextFrame>("textframe", Path.Combine(templatesPath, "textframe.html"));
171+
document.Input.AddTemplate<Paragraph>("paragraph", Path.Combine(templatesPath, "paragraph.html"));
172+
document.Input.AddTemplate<Paragraph>("bullet", Path.Combine(templatesPath, "bullet.html"));
173+
document.Input.AddTemplate<Portion>("portion", Path.Combine(templatesPath, "portion.html"));
174+
document.Input.AddTemplate<VideoFrame>("videoframe", Path.Combine(templatesPath, "videoframe.html"));
175+
document.Input.AddTemplate<PictureFrame>("pictureframe", Path.Combine(templatesPath, "pictureframe.html")); ;
176+
document.Input.AddTemplate<Shape>("shape", Path.Combine(templatesPath, "shape.html"));
177+
178+
AddSinglePageCommonOutput(pres, document, outputPath);
140179

180+
AddResourcesOutput(pres, document, embedImages);
181+
182+
AddScriptsOutput(document, templatesPath);
183+
}
184+
185+
static void SetupGlobals(WebDocument document, WebDocumentOptions options, string outputPath)
186+
{
187+
PresentationExtensions.SetGlobals(document, options, outputPath);
188+
189+
document.Global.Put("slidesPath", outputPath);
190+
document.Global.Put("stylesPath", outputPath);
191+
document.Global.Put("scriptsPath", outputPath);
192+
}
193+
194+
private static void AddCommonStylesTemplates(WebDocument document, string templatesPath)
195+
{
141196
document.Input.AddTemplate<Presentation>("styles-pres", Path.Combine(templatesPath, @"styles\pres.css"));
142197
document.Input.AddTemplate<MasterSlide>("styles-master", Path.Combine(templatesPath, @"styles\master.css"));
143198
document.Input.AddTemplate<Presentation>("scripts-animation",
144199
Path.Combine(templatesPath, @"scripts\animation.js"));
200+
}
145201

202+
private static void AddCommonShapeTemplates(WebDocument document, string templatesPath)
203+
{
146204
document.Input.AddTemplate<Slide>("slide", Path.Combine(templatesPath, "slide.html"));
147205
document.Input.AddTemplate<AutoShape>("autoshape", Path.Combine(templatesPath, "autoshape.html"));
148206
document.Input.AddTemplate<TextFrame>("textframe", Path.Combine(templatesPath, "textframe.html"));
149207
document.Input.AddTemplate<Paragraph>("paragraph", Path.Combine(templatesPath, "paragraph.html"));
150208
document.Input.AddTemplate<Paragraph>("bullet", Path.Combine(templatesPath, "bullet.html"));
151209
document.Input.AddTemplate<Portion>("portion", Path.Combine(templatesPath, "portion.html"));
152-
153210
document.Input.AddTemplate<VideoFrame>("videoframe", Path.Combine(templatesPath, "videoframe.html"));
154-
155-
document.Input.AddTemplate<PictureFrame>("pictureframe", Path.Combine(templatesPath, "pictureframe.html")); ;
211+
document.Input.AddTemplate<PictureFrame>("pictureframe", Path.Combine(templatesPath, "pictureframe.html"));
212+
document.Input.AddTemplate<Table>("table", Path.Combine(templatesPath, "table.html"));
156213
document.Input.AddTemplate<Shape>("shape", Path.Combine(templatesPath, "shape.html"));
214+
}
157215

216+
private static void AddSinglePageCommonOutput(Presentation pres, WebDocument document, string outputPath)
217+
{
218+
string stylesPath = document.Global.Get<string>("stylesPath");
219+
string scriptsPath = document.Global.Get<string>("scriptsPath");
220+
158221
document.Output.Add(Path.Combine(outputPath, "index.html"), "index", pres);
159222
document.Output.Add(Path.Combine(stylesPath, "pres.css"), "styles-pres", pres);
160-
document.Output.Add(Path.Combine(stylesPath, "master.css"), "styles-master", (MasterSlide) pres.Masters[0]);
223+
document.Output.Add(Path.Combine(stylesPath, "master.css"), "styles-master", (MasterSlide)pres.Masters[0]);
161224
document.Output.Add(Path.Combine(scriptsPath, "animation.js"), "scripts-animation", pres);
225+
}
226+
227+
private static void AddScriptsOutput(WebDocument document, string templatesPath)
228+
{
229+
string scriptsPath = document.Global.Get<string>("scriptsPath");
162230

163-
document.AddEmbeddedFontsOutput(document.Global.Get<string>("fontsPath"), pres);
164-
document.AddVideoOutput(document.Global.Get<string>("mediaPath"), pres);
165231
document.AddScriptsOutput(scriptsPath, Path.Combine(templatesPath, @"scripts\jquery-3.5.1.min.js"), "jquery.js");
166232
document.AddScriptsOutput(scriptsPath, Path.Combine(templatesPath, @"scripts\anime.min.js"), "anime.js");
167233
}
234+
235+
private static void AddResourcesOutput(Presentation pres, WebDocument document, bool embedImages)
236+
{
237+
document.AddEmbeddedFontsOutput(document.Global.Get<string>("fontsPath"), pres);
238+
document.AddVideoOutput(document.Global.Get<string>("mediaPath"), pres);
239+
240+
if (!embedImages)
241+
{
242+
string imagesPath = document.Global.Get<string>("imagesPath");
243+
document.AddImagesOutput(imagesPath, pres);
244+
document.AddShapeAsImagesOutput<Chart>(imagesPath, pres);
245+
document.AddShapeAsImagesOutput<SmartArt>(imagesPath, pres);
246+
document.AddShapeAsImagesOutput<AutoShape>(imagesPath, pres);
247+
document.AddShapeAsImagesOutput<Connector>(imagesPath, pres);
248+
document.AddShapeAsImagesOutput<GroupShape>(imagesPath, pres);
249+
}
250+
}
168251
}
169252
}

Examples/SinglePageApp/SinglePageApp.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
</ProjectReference>
6464
</ItemGroup>
6565
<ItemGroup>
66+
<Content Include="custom-templates\index-inline-css.html">
67+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
68+
</Content>
6669
<Content Include="custom-templates\index-table-custom-style.html">
6770
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6871
</Content>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@model TemplateContext<Presentation>
2+
3+
@{
4+
Presentation contextObject = Model.Object;
5+
}
6+
7+
<!DOCTYPE html>
8+
9+
<html
10+
xmlns="http://www.w3.org/1999/xhtml"
11+
xmlns:svg="http://www.w3.org/2000/svg"
12+
xmlns:xlink="http://www.w3.org/1999/xlink">
13+
<head>
14+
<meta charset="utf-8" />
15+
<title>@contextObject.DocumentProperties.Title</title>
16+
<link rel="stylesheet" type="text/css" href="pres.css" />
17+
<link rel="stylesheet" type="text/css" href="master.css" />
18+
<script src="jquery.js"></script>
19+
<script src="anime.js"></script>
20+
<script src="animation.js"></script>
21+
22+
<!-- Inline CSS -->
23+
<style>
24+
body {
25+
background-color: blue;
26+
}
27+
</style>
28+
<!-- Inline CSS -->
29+
30+
</head>
31+
<body>
32+
<div class="bg">
33+
<div id="flash" class="slide" style="background-color: #FFFFFF; outline: 0; display: none;">
34+
</div>
35+
<div id="blackboard" class="slide" style="background-color: #000000; outline: 0; display: none;">
36+
</div>
37+
38+
@foreach (Slide slide in contextObject.Slides)
39+
{
40+
if (slide.Hidden)
41+
{
42+
continue;
43+
}
44+
45+
@Include("slide", Model.SubModel(slide))
46+
}
47+
</div>
48+
49+
<button class="navigation" id="PrevSlide" style="left: @(Model.Object.SlideSize.Size.Width / 2 - 100 - 5)px; top: @(Model.Object.SlideSize.Size.Height + 40)px;">Prev Slide</button>
50+
<button class="navigation" id="NextSlide" style="left: @(Model.Object.SlideSize.Size.Width / 2 + 5)px; top: @(Model.Object.SlideSize.Size.Height + 40)px;">Next Slide</button>
51+
52+
<div id="svgdiv">
53+
<svg width="0" height="0" xmlns="http://www.w3.org/2000/svg" style="width: 100%; height: auto;">
54+
<defs>
55+
<clipPath id="effectsclip" viewbox="0 0 @Model.Object.SlideSize.Size.Width @Model.Object.SlideSize.Size.Height">
56+
</clipPath>
57+
</defs>
58+
</svg>
59+
</div>
60+
</body>
61+
</html>

0 commit comments

Comments
 (0)