11using System ;
22using System . IO ;
33using Aspose . Slides ;
4+ using Aspose . Slides . Charts ;
45using Aspose . Slides . Export . Web ;
6+ using Aspose . Slides . SmartArt ;
57using Aspose . Slides . WebExtensions ;
68
79namespace 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}
0 commit comments