private static void CheckArguments(WebDocumentOptions options, string templatesPath, string outputPath) { if (options == null) { throw new ArgumentNullException("options"); } if (templatesPath == null) { throw new ArgumentNullException("templatesPath"); } if (!Directory.Exists(templatesPath)) { throw new ArgumentException("Specified templates path doesn't exist.", "templatesPath"); } if (options.TemplateEngine == null) { options.TemplateEngine = new RazorTemplateEngine(); } if (options.OutputSaver == null) { options.OutputSaver = new FileOutputSaver(); } }
public static WebDocument ToMultiPageWebDocument( this Presentation pres, WebDocumentOptions options, string templatesPath, string outputPath) { CheckArguments(options, templatesPath, outputPath); WebDocument document = new WebDocument(options); SetGlobals(document, options, outputPath); const string localSlidesPath = "slides"; string slidesPath = Path.Combine(outputPath, localSlidesPath); string stylesPath = Path.Combine(outputPath, "styles"); string scriptsPath = Path.Combine(outputPath, "scripts"); document.Global.Put("slidesPath", slidesPath); document.Global.Put("stylesPath", stylesPath); document.Global.Put("scriptsPath", scriptsPath); document.AddCommonInputOutput(options, templatesPath, outputPath, pres); document.AddMultiPageInputTemplates(templatesPath); document.AddMultiPageOutputFiles(outputPath, slidesPath, localSlidesPath, pres); if (!options.EmbedImages) { document.AddThumbnailsOutput(document.Global.Get <string>("imagesPath"), pres); } return(document); }
static void ExportHelloWorld() { using (Presentation pres = new Presentation()) { IAutoShape shape = pres.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 10, 10, 100, 150); shape.TextFrame.Text = "Hello World"; WebDocumentOptions options = new WebDocumentOptions { TemplateEngine = new RazorTemplateEngine(), // we will use Razor template engine, other template engines can be used by implementing ITemplateEngine OutputSaver = new FileOutputSaver() // other result savers can be used by implementing IOutputSaver interface }; WebDocument document = new WebDocument(options); // add document "input" - what source will be used to generate HTML document document.Input .AddTemplate <Presentation>( // template will have Presentation as a "model" object (Model.Object) "index", // template key - needed by template engine to match an object (Presentation) to the template loaded from disk ("shape-template-hello-world.html") @"custom-templates\\shape-template-hello-world.html"); // add output - how resulting HTML document will looks like when it will be exported to the disk document.Output.Add( "hello-world.html", // output file path "index", // template key that will be used for this file (we set it in a previous statement) pres); // an actual Model.Object instance document.Save(); } }
static void ExportHelloWorldWithInlineCss() { using (Presentation pres = new Presentation("demo.pptx")) { WebDocumentOptions options = new WebDocumentOptions { TemplateEngine = new RazorTemplateEngine(), OutputSaver = new FileOutputSaver() }; WebDocument document = new WebDocument(options); const string templatesPath = "templates\\single-page"; const string outputPath = "inline-css"; // setup global document values SetupGlobals(document, options, outputPath); document.Input.AddTemplate <Presentation>("index", @"custom-templates\index-inline-css.html"); AddCommonStylesTemplates(document, templatesPath); AddCommonShapeTemplates(document, templatesPath); AddSinglePageCommonOutput(pres, document, outputPath); AddResourcesOutput(pres, document, options.EmbedImages); AddScriptsOutput(document, templatesPath); document.Save(); } }
static void ExportCustomTableStyles() { using (Presentation pres = new Presentation("table.pptx")) { const string templatesPath = "templates\\single-page"; const string outputPath = "custom-table-styles"; var options = new WebDocumentOptions { TemplateEngine = new RazorTemplateEngine(), OutputSaver = new FileOutputSaver(), EmbedImages = false }; // setup global document values WebDocument document = new WebDocument(options); SetupGlobals(document, options, outputPath); // add common structure (except table template) ExportCustomTableStyles_AddCommonStructure(pres, document, templatesPath, outputPath, options.EmbedImages); // add custom table template document.Input.AddTemplate <Table>("table", @"custom-templates\table-custom-style.html"); // add custom table styles document.Input.AddTemplate <Presentation>("table-custom-style", @"custom-templates\styles\table-custom-style.css"); document.Output.Add(Path.Combine(outputPath, "table-custom-style.css"), "table-custom-style", pres); // add custom index - it's just a copy of the standard "index.html", but includes a reference to "table-custom-style.css" document.Input.AddTemplate <Presentation>("index", @"custom-templates\index-table-custom-style.html"); document.Save(); } }
static void SetupGlobals(WebDocument document, WebDocumentOptions options, string outputPath) { PresentationExtensions.SetGlobals(document, options, outputPath); document.Global.Put("slidesPath", outputPath); document.Global.Put("stylesPath", outputPath); document.Global.Put("scriptsPath", outputPath); }
public static WebDocument ToMultiPageWebDocument( this Presentation pres, string templatesPath, string outputPath) { var options = new WebDocumentOptions { TemplateEngine = new RazorTemplateEngine(), OutputSaver = new FileOutputSaver(), EmbedImages = false }; return(ToMultiPageWebDocument(pres, options, templatesPath, outputPath)); }
public static void SetGlobals(WebDocument document, WebDocumentOptions options, string outputPath) { string imagesPath = Path.Combine(outputPath, "images"); string fontsPath = Path.Combine(outputPath, "fonts"); string mediaPath = Path.Combine(outputPath, "media"); document.Global.Put("slideMargin", 10); document.Global.Put("embedImages", options.EmbedImages); document.Global.Put("animateTransitions", options.AnimateTransitions); document.Global.Put("animateShapes", options.AnimateShapes); document.Global.Put("navigationEnabled", false); document.Global.Put("imagesPath", imagesPath); document.Global.Put("fontsPath", fontsPath); document.Global.Put("mediaPath", mediaPath); }
static void ExportDefaultAnimated() { using (Presentation pres = new Presentation("demo-transitions.pptx")) { WebDocumentOptions options = new WebDocumentOptions { TemplateEngine = new RazorTemplateEngine(), OutputSaver = new FileOutputSaver(), AnimateTransitions = true }; WebDocument document = pres.ToSinglePageWebDocument(options, "templates\\single-page", @"single-page-animated-output"); document.Save(); } }
public static void AddCommonInputOutput(this WebDocument document, WebDocumentOptions options, string templatesPath, string outputPath, Presentation pres) { string stylesPath = document.Global.Get <string>("stylesPath"); string scriptsPath = document.Global.Get <string>("scriptsPath"); document.Input.AddTemplate <Presentation>("styles-pres", Path.Combine(templatesPath, @"styles\pres.css")); document.Input.AddTemplate <MasterSlide>("styles-master", Path.Combine(templatesPath, @"styles\master.css")); document.Input.AddTemplate <Presentation>("scripts-animation", Path.Combine(templatesPath, @"scripts\animation.js")); document.Input.AddTemplate <Presentation>("scripts-effects", Path.Combine(templatesPath, @"scripts\effects.js")); document.Input.AddTemplate <Presentation>("scripts-navigation", Path.Combine(templatesPath, @"scripts\navigation.js")); document.Input.AddTemplate <Presentation>("index", Path.Combine(templatesPath, "index.html")); document.Input.AddTemplate <Slide>("slide", Path.Combine(templatesPath, "slide.html")); document.Input.AddTemplate <AutoShape>("autoshape", Path.Combine(templatesPath, "autoshape.html")); document.Input.AddTemplate <TextFrame>("textframe", Path.Combine(templatesPath, "textframe.html")); document.Input.AddTemplate <Paragraph>("paragraph", Path.Combine(templatesPath, "paragraph.html")); document.Input.AddTemplate <Paragraph>("bullet", Path.Combine(templatesPath, "bullet.html")); document.Input.AddTemplate <Portion>("portion", Path.Combine(templatesPath, "portion.html")); document.Input.AddTemplate <VideoFrame>("videoframe", Path.Combine(templatesPath, "videoframe.html")); document.Input.AddTemplate <PictureFrame>("pictureframe", Path.Combine(templatesPath, "pictureframe.html")); document.Input.AddTemplate <Table>("table", Path.Combine(templatesPath, "table.html")); document.Input.AddTemplate <Shape>("shape", Path.Combine(templatesPath, "shape.html")); document.Output.Add(Path.Combine(outputPath, "index.html"), "index", pres); document.Output.Add(Path.Combine(stylesPath, "pres.css"), "styles-pres", pres); document.Output.Add(Path.Combine(stylesPath, "master.css"), "styles-master", (MasterSlide)pres.Masters[0]); document.Output.Add(Path.Combine(scriptsPath, "animation.js"), "scripts-animation", pres); document.Output.Add(Path.Combine(scriptsPath, "effects.js"), "scripts-effects", pres); document.Output.Add(Path.Combine(scriptsPath, "navigation.js"), "scripts-navigation", pres); document.AddEmbeddedFontsOutput(document.Global.Get <string>("fontsPath"), pres); document.AddVideoOutput(document.Global.Get <string>("mediaPath"), pres); if (!options.EmbedImages) { string imagesPath = document.Global.Get <string>("imagesPath"); document.AddImagesOutput(imagesPath, pres); document.AddShapeAsImagesOutput <Chart>(imagesPath, pres); document.AddShapeAsImagesOutput <SmartArt.SmartArt>(imagesPath, pres); document.AddShapeAsImagesOutput <AutoShape>(imagesPath, pres); document.AddShapeAsImagesOutput <Connector>(imagesPath, pres); document.AddShapeAsImagesOutput <GroupShape>(imagesPath, pres); } }
static void ExportHelloWorldWithStyles() { using (Presentation pres = new Presentation()) { IAutoShape shape = pres.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 10, 10, 100, 150); shape.TextFrame.Text = "Hello World"; WebDocumentOptions options = new WebDocumentOptions { TemplateEngine = new RazorTemplateEngine(), OutputSaver = new FileOutputSaver() }; WebDocument document = new WebDocument(options); document.Input.AddTemplate <Presentation>("index", @"custom-templates\shape-template-hello-world.html"); document.Input.AddTemplate <Presentation>("styles", @"custom-templates\styles\shape-template-hello-world.css"); document.Output.Add("hello-world.html", "index", pres); document.Output.Add("hello-world.css", "styles", pres); document.Save(); } }
public static WebDocument ToSinglePageWebDocument( this Presentation pres, WebDocumentOptions options, string templatesPath, string outputPath) { CheckArguments(options, templatesPath, outputPath); WebDocument document = new WebDocument(options); SetGlobals(document, options, outputPath); document.Global.Put("slidesPath", outputPath); document.Global.Put("stylesPath", outputPath); document.Global.Put("scriptsPath", outputPath); document.AddCommonInputOutput(options, templatesPath, outputPath, pres); if (!options.EmbedImages) { document.AddThumbnailsOutput(document.Global.Get <string>("imagesPath"), pres); } return(document); }
static void ExportBySections() { using (Presentation pres = new Presentation("demo-transitions.pptx")) { const string templatesPath = "templates\\multi-page"; const string outputPath = "multi-page-by-sections"; var options = new WebDocumentOptions { TemplateEngine = new RazorTemplateEngine(), OutputSaver = new FileOutputSaver(), EmbedImages = false }; // setup global document values WebDocument document = new WebDocument(options); PresentationExtensions.SetGlobals(document, options, outputPath); const string localSlidesPath = "slides"; string slidesPath = Path.Combine(outputPath, localSlidesPath); string stylesPath = Path.Combine(outputPath, "styles"); string scriptsPath = Path.Combine(outputPath, "scripts"); document.Global.Put("slidesPath", slidesPath); document.Global.Put("stylesPath", stylesPath); document.Global.Put("scriptsPath", scriptsPath); // setup folder-by-section folders structure foreach (ISection section in pres.Sections) { foreach (Slide slide in section.GetSlidesListOfSection()) { if (slide.Hidden) { continue; } string subPath = Path.Combine(section.Name, string.Format("slide{0}.html", slide.SlideNumber)); string path = Path.Combine(outputPath, subPath); string key = string.Format("slide{0}path", slide.SlideNumber); document.Global.Put(key, subPath); document.Output.Add(path, "slide", slide); } } // setup rest of the document properties document.AddCommonInputOutput(options, templatesPath, outputPath, pres); document.AddMultiPageInputTemplates(templatesPath); document.Output.Add(Path.Combine(outputPath, "menu.html"), "menu", pres); if (!options.EmbedImages) { document.AddThumbnailsOutput(document.Global.Get <string>("imagesPath"), pres); } document.Save(); } }