1
1
using System ;
2
2
using System . IO ;
3
3
using Aspose . Slides ;
4
+ using Aspose . Slides . Charts ;
4
5
using Aspose . Slides . Export . Web ;
6
+ using Aspose . Slides . SmartArt ;
5
7
using Aspose . Slides . WebExtensions ;
6
8
7
9
namespace SinglePageApp
@@ -10,7 +12,10 @@ class Program
10
12
{
11
13
static void Main ( string [ ] args )
12
14
{
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 ( ) ;
14
19
15
20
Console . WriteLine ( "HTML export is complete..." ) ;
16
21
}
@@ -90,6 +95,32 @@ static void ExportHelloWorldWithStyles()
90
95
}
91
96
}
92
97
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
+
93
124
static void ExportCustomTableStyles ( )
94
125
{
95
126
using ( Presentation pres = new Presentation ( "table.pptx" ) )
@@ -106,17 +137,10 @@ static void ExportCustomTableStyles()
106
137
107
138
// setup global document values
108
139
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 ) ;
117
141
118
142
// add common structure (except table template)
119
- ExportCustomTableStyles_AddCommonStructure ( pres , document , templatesPath , outputPath ) ;
143
+ ExportCustomTableStyles_AddCommonStructure ( pres , document , templatesPath , outputPath , options . EmbedImages ) ;
120
144
121
145
// add custom table template
122
146
document . Input . AddTemplate < Table > ( "table" , @"custom-templates\table-custom-style.html" ) ;
@@ -132,38 +156,97 @@ static void ExportCustomTableStyles()
132
156
}
133
157
}
134
158
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 )
137
165
{
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 ) ;
140
179
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
+ {
141
196
document . Input . AddTemplate < Presentation > ( "styles-pres" , Path . Combine ( templatesPath , @"styles\pres.css" ) ) ;
142
197
document . Input . AddTemplate < MasterSlide > ( "styles-master" , Path . Combine ( templatesPath , @"styles\master.css" ) ) ;
143
198
document . Input . AddTemplate < Presentation > ( "scripts-animation" ,
144
199
Path . Combine ( templatesPath , @"scripts\animation.js" ) ) ;
200
+ }
145
201
202
+ private static void AddCommonShapeTemplates ( WebDocument document , string templatesPath )
203
+ {
146
204
document . Input . AddTemplate < Slide > ( "slide" , Path . Combine ( templatesPath , "slide.html" ) ) ;
147
205
document . Input . AddTemplate < AutoShape > ( "autoshape" , Path . Combine ( templatesPath , "autoshape.html" ) ) ;
148
206
document . Input . AddTemplate < TextFrame > ( "textframe" , Path . Combine ( templatesPath , "textframe.html" ) ) ;
149
207
document . Input . AddTemplate < Paragraph > ( "paragraph" , Path . Combine ( templatesPath , "paragraph.html" ) ) ;
150
208
document . Input . AddTemplate < Paragraph > ( "bullet" , Path . Combine ( templatesPath , "bullet.html" ) ) ;
151
209
document . Input . AddTemplate < Portion > ( "portion" , Path . Combine ( templatesPath , "portion.html" ) ) ;
152
-
153
210
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" ) ) ;
156
213
document . Input . AddTemplate < Shape > ( "shape" , Path . Combine ( templatesPath , "shape.html" ) ) ;
214
+ }
157
215
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
+
158
221
document . Output . Add ( Path . Combine ( outputPath , "index.html" ) , "index" , pres ) ;
159
222
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 ] ) ;
161
224
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" ) ;
162
230
163
- document . AddEmbeddedFontsOutput ( document . Global . Get < string > ( "fontsPath" ) , pres ) ;
164
- document . AddVideoOutput ( document . Global . Get < string > ( "mediaPath" ) , pres ) ;
165
231
document . AddScriptsOutput ( scriptsPath , Path . Combine ( templatesPath , @"scripts\jquery-3.5.1.min.js" ) , "jquery.js" ) ;
166
232
document . AddScriptsOutput ( scriptsPath , Path . Combine ( templatesPath , @"scripts\anime.min.js" ) , "anime.js" ) ;
167
233
}
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
+ }
168
251
}
169
252
}
0 commit comments