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);
        }
Beispiel #2
0
        /// <summary>
        ///     Determines whether [is allowed extension] [the specified extension].
        /// </summary>
        /// <param name="extension">The extension.</param>
        /// <param name="fileType">Type of the file.</param>
        /// <returns></returns>
        /// <createdOn>1/27/2016 8:00 AM</createdOn>
        /// <exception cref="System.ArgumentOutOfRangeException">null</exception>
        public static bool IsAllowedExtension(string extension, FileType fileType = FileType.Image)
        {
            var isAllowed = false;

            switch (fileType)
            {
            case FileType.Image:
                isAllowed = ImageExtensions.Contains(extension);
                break;

            case FileType.Document:
                isAllowed = DocumentExtensions.Contains(extension);
                break;

            case FileType.Presentation:
                isAllowed = PresentationExtensions.Contains(extension);
                break;

            case FileType.Spreadsheet:
                isAllowed = SpreadsheetExtensions.Contains(extension);
                break;

            case FileType.CompressedFile:
                isAllowed = CompressedFileExtensions.Contains(extension);
                break;

            case FileType.Website:
                isAllowed = WebsiteExtensions.Contains(extension);
                break;

            case FileType.Sound:
                isAllowed = SoundExtensions.Contains(extension);
                break;

            case FileType.Video:
                isAllowed = VideoExtensions.Contains(extension);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null);
            }

            return(isAllowed);
        }
        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();
            }
        }