static void Main(string[] args)
        {
            //Loading a presentation
            using (Presentation pres = new Presentation("example.pptx"))
            {
                const string path = "path";
                const string fileName = "video.html";
                const string baseUri = "http://www.example.com/";

                VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path: path, fileName: fileName, baseUri: baseUri);

                //Setting HTML options
                HtmlOptions htmlOptions = new HtmlOptions(controller);
                SVGOptions svgOptions = new SVGOptions(controller);

                htmlOptions.HtmlFormatter = HtmlFormatter.CreateCustomFormatter(controller);
                htmlOptions.SlideImageFormat = SlideImageFormat.Svg(svgOptions);

                //Saving the file
                pres.Save(path + fileName, SaveFormat.Html, htmlOptions);
            }
        }
Ejemplo n.º 2
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Conversion();

            // Loading a presentation
            using (Presentation pres = new Presentation(dataDir + "Media File.pptx"))
            {
                string       path     = dataDir;
                const string fileName = "ExportMediaFiles_out.html";
                const string baseUri  = "http://www.example.com/";

                VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path, fileName, baseUri);

                // Setting HTML options
                HtmlOptions htmlOptions = new HtmlOptions(controller);
                SVGOptions  svgOptions  = new SVGOptions(controller);

                htmlOptions.HtmlFormatter    = HtmlFormatter.CreateCustomFormatter(controller);
                htmlOptions.SlideImageFormat = SlideImageFormat.Svg(svgOptions);

                // Saving the file
                pres.Save(Path.Combine(path, fileName), SaveFormat.Html, htmlOptions);
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Conversion();

            // Loading a presentation
            using (Presentation pres = new Presentation(dataDir + "Media File.pptx"))
            {
                string path = dataDir;
                const string fileName = "ExportMediaFiles_out.html";
                const string baseUri = "http://www.example.com/";

                VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path, fileName, baseUri);

                // Setting HTML options
                HtmlOptions htmlOptions = new HtmlOptions(controller);
                SVGOptions svgOptions = new SVGOptions(controller);

                htmlOptions.HtmlFormatter = HtmlFormatter.CreateCustomFormatter(controller);
                htmlOptions.SlideImageFormat = SlideImageFormat.Svg(svgOptions);

                // Saving the file
                pres.Save(Path.Combine(path, fileName), SaveFormat.Html, htmlOptions);
            }
        }
        public static void Run()
        {
            //ExStart:GeneratingSVGWithCustomShapeIDS
            string dataDir = RunExamples.GetDataDir_Conversion();

            using (Presentation pres = new Presentation(dataDir + "presentation.pptx"))
            {
                using (FileStream stream = new FileStream(dataDir + "pptxFileName.svg", FileMode.OpenOrCreate))
                {
                    SVGOptions svgOptions = new SVGOptions
                    {
                        ShapeFormattingController = new CustomSvgShapeFormattingController()
                    };

                    pres.Slides[0].WriteAsSvg(stream, svgOptions);
                }
            }
            //ExEnd:GeneratingSVGWithCustomShapeIDS
        }
Ejemplo n.º 5
0
        public static void Run()
        {
            string dataDir        = RunExamples.GetDataDir_Conversion();
            string pptxFileName   = Path.Combine(dataDir, "Convert_Svg_Custom.pptx");
            string outSvgFileName = Path.Combine(RunExamples.OutPath, "Convert_Svg_Custom.svg");

            using (Presentation pres = new Presentation(pptxFileName))
            {
                using (FileStream stream = new FileStream(outSvgFileName, FileMode.Create))
                {
                    SVGOptions svgOptions = new SVGOptions
                    {
                        ShapeFormattingController = new MySvgShapeFormattingController()
                    };

                    pres.Slides[0].WriteAsSvg(stream, svgOptions);
                }
            }
        }
Ejemplo n.º 6
0
        public static void Run()
        {
            //ExStart:ConvertWholePresentationToHTMLWithMediaFiles
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Conversion();
           const string htmlDocumentFileName = "presentationWithVideo.html";
          using (Presentation pres = new Presentation("presentationWith.pptx"))
        {
        VideoPlayerHtmlController controller = new VideoPlayerHtmlController(
        "", htmlDocumentFileName, "http://www.example.com/");

        HtmlOptions htmlOptions = new HtmlOptions(controller);
        SVGOptions svgOptions = new SVGOptions(controller);

        htmlOptions.HtmlFormatter = HtmlFormatter.CreateCustomFormatter(controller);
        htmlOptions.SlideImageFormat = SlideImageFormat.Svg(svgOptions);

        pres.Save(htmlDocumentFileName, SaveFormat.Html, htmlOptions);
}
            }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            //Loading a presentation
            using (Presentation pres = new Presentation("example.pptx"))
            {
                const string path     = "path";
                const string fileName = "video.html";
                const string baseUri  = "http://www.example.com/";

                VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path: path, fileName: fileName, baseUri: baseUri);

                //Setting HTML options
                HtmlOptions htmlOptions = new HtmlOptions(controller);
                SVGOptions  svgOptions  = new SVGOptions(controller);

                htmlOptions.HtmlFormatter    = HtmlFormatter.CreateCustomFormatter(controller);
                htmlOptions.SlideImageFormat = SlideImageFormat.Svg(svgOptions);

                //Saving the file
                pres.Save(path + fileName, SaveFormat.Html, htmlOptions);
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            string FilePath     = @"..\..\..\Sample Files\";
            string srcFileName  = FilePath + "Conversion.pptx";
            string destFileName = "video.html";

            //Loading a presentation
            using (Presentation pres = new Presentation(srcFileName))
            {
                const string baseUri = "http://www.example.com/";

                VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path: FilePath, fileName: destFileName, baseUri: baseUri);

                //Setting HTML options
                HtmlOptions htmlOptions = new HtmlOptions(controller);
                SVGOptions  svgOptions  = new SVGOptions(controller);

                htmlOptions.HtmlFormatter    = HtmlFormatter.CreateCustomFormatter(controller);
                htmlOptions.SlideImageFormat = SlideImageFormat.Svg(svgOptions);

                //Saving the file
                pres.Save(destFileName, SaveFormat.Html, htmlOptions);
            }
        }
        static void Main(string[] args)
        {
            string FilePath = @"..\..\..\Sample Files\";
            string srcFileName = FilePath + "Conversion.pptx";
            string destFileName =  "video.html";
            
            //Loading a presentation
            using (Presentation pres = new Presentation(srcFileName))
            {
                const string baseUri = "http://www.example.com/";

                VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path: FilePath, fileName: destFileName, baseUri: baseUri);

                //Setting HTML options
                HtmlOptions htmlOptions = new HtmlOptions(controller);
                SVGOptions svgOptions = new SVGOptions(controller);

                htmlOptions.HtmlFormatter = HtmlFormatter.CreateCustomFormatter(controller);
                htmlOptions.SlideImageFormat = SlideImageFormat.Svg(svgOptions);

                //Saving the file
                pres.Save(destFileName, SaveFormat.Html, htmlOptions);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Converts source file into target format, saves resulted file to out file.
        /// Returns null in case of multiple files (all saved into outFolder).
        /// </summary>
        /// <param name="sourceFile">Source slides file to proceed.</param>
        /// <param name="outFolder">Output folder.</param>
        /// <param name="format">Output format.</param>
        /// <returns>Result file path.</returns>
        public string Conversion(
            string sourceFile,
            string outFolder,
            SlidesConversionFormat format
            )
        {
            using (var presentation = new Presentation(sourceFile))
            {
                var fileName   = Path.GetFileNameWithoutExtension(sourceFile);
                var outOneFile = Path.Combine(outFolder, $"{fileName}.{format}");

                switch (format)
                {
                case SlidesConversionFormat.odp:
                case SlidesConversionFormat.otp:
                case SlidesConversionFormat.pptx:
                case SlidesConversionFormat.pptm:
                case SlidesConversionFormat.potx:
                case SlidesConversionFormat.ppt:
                case SlidesConversionFormat.pps:
                case SlidesConversionFormat.ppsm:
                case SlidesConversionFormat.pot:
                case SlidesConversionFormat.potm:
                case SlidesConversionFormat.pdf:
                case SlidesConversionFormat.xps:
                case SlidesConversionFormat.ppsx:
                case SlidesConversionFormat.tiff:
                case SlidesConversionFormat.html:
                case SlidesConversionFormat.swf:
                    var slidesFormat = format.ToString().ParseEnum <SaveFormat>();
                    presentation.Save(outOneFile, slidesFormat);
                    return(outOneFile);

                case SlidesConversionFormat.txt:
                    var lines = new List <string>();
                    foreach (var slide in presentation.Slides)
                    {
                        foreach (var shp in slide.Shapes)
                        {
                            if (shp is AutoShape ashp)
                            {
                                lines.Add(ashp.TextFrame.Text);
                            }
                        }

                        var notes = slide.NotesSlideManager.NotesSlide?.NotesTextFrame?.Text;

                        if (!string.IsNullOrEmpty(notes))
                        {
                            lines.Add(notes);
                        }
                    }
                    System.IO.File.WriteAllLines(outOneFile, lines);
                    return(outOneFile);

                case SlidesConversionFormat.doc:
                case SlidesConversionFormat.docx:
                    using (var stream = new MemoryStream())
                    {
                        presentation.Save(stream, SaveFormat.Html);
                        stream.Flush();
                        stream.Seek(0, SeekOrigin.Begin);

                        var doc = new Words.Document(stream);
                        switch (format)
                        {
                        case SlidesConversionFormat.doc:
                            doc.Save(outOneFile, Words.SaveFormat.Doc);
                            break;

                        case SlidesConversionFormat.docx:
                            doc.Save(outOneFile, Words.SaveFormat.Docx);
                            break;

                        default:
                            throw new ArgumentException($"Unknown format {format}");
                        }
                    }
                    return(outOneFile);

                case SlidesConversionFormat.bmp:
                case SlidesConversionFormat.jpeg:
                case SlidesConversionFormat.png:
                case SlidesConversionFormat.emf:
                case SlidesConversionFormat.wmf:
                case SlidesConversionFormat.gif:
                case SlidesConversionFormat.exif:
                case SlidesConversionFormat.ico:
                    ImageFormat GetImageFormat(SlidesConversionFormat f)
                    {
                        switch (format)
                        {
                        case SlidesConversionFormat.bmp:
                            return(ImageFormat.Bmp);

                        case SlidesConversionFormat.jpeg:
                            return(ImageFormat.Jpeg);

                        case SlidesConversionFormat.png:
                            return(ImageFormat.Png);

                        case SlidesConversionFormat.emf:
                            return(ImageFormat.Wmf);

                        case SlidesConversionFormat.wmf:
                            return(ImageFormat.Wmf);

                        case SlidesConversionFormat.gif:
                            return(ImageFormat.Gif);

                        case SlidesConversionFormat.exif:
                            return(ImageFormat.Emf);

                        case SlidesConversionFormat.ico:
                            return(ImageFormat.Icon);

                        default:
                            throw new ArgumentException($"Unknown format {format}");
                        }
                    }

                    ///var size = presentation.SlideSize.Size;

                    for (var i = 0; i < presentation.Slides.Count; i++)
                    {
                        var slide   = presentation.Slides[i];
                        var outFile = Path.Combine(outFolder, $"{i}.{format}");
                        using (var bitmap = slide.GetThumbnail(1, 1))                                // (new Size((int)size.Width, (int)size.Height)))
                            bitmap.Save(outFile, GetImageFormat(format));
                    }

                    return(null);

                case SlidesConversionFormat.svg:
                    var svgOptions = new SVGOptions
                    {
                        PicturesCompression = PicturesCompression.DocumentResolution
                    };

                    for (var i = 0; i < presentation.Slides.Count; i++)
                    {
                        var slide   = presentation.Slides[i];
                        var outFile = Path.Combine(outFolder, $"{i}.{format}");
                        using (var stream = new FileStream(outFile, FileMode.CreateNew))
                            slide.WriteAsSvg(stream, svgOptions);
                    }

                    return(null);

                default:
                    throw new ArgumentException($"Unknown format {format}");
                }
            }
        }
        public string Conversion(
            string sourceFile,
            string outFolder,
            string format
            )
        {
            using (var presentation = new Presentation(sourceFile))
            {
                var fileName   = Path.GetFileNameWithoutExtension(sourceFile);
                var outOneFile = Path.Combine(outFolder, $"{fileName}.{format}");

                switch (format)
                {
                case "odp":
                case "otp":
                case "pptx":
                case "pptm":
                case "potx":
                case "ppt":
                case "pps":
                case "ppsm":
                case "pot":
                case "potm":
                case "pdf":
                case "xps":
                case "ppsx":
                case "tiff":
                case "html":
                case "swf":
                    var slidesFormat = format.ToString().ParseEnum <SaveFormat>();
                    presentation.Save(outOneFile, slidesFormat);
                    return(outOneFile);

                case "txt":
                    var lines = new List <string>();
                    foreach (var slide in presentation.Slides)
                    {
                        foreach (var shp in slide.Shapes)
                        {
                            if (shp.Placeholder != null)
                            {
                                lines.Add(((AutoShape)shp).TextFrame.Text);
                            }
                        }

                        var notes = slide.NotesSlideManager.NotesSlide?.NotesTextFrame?.Text;

                        if (!string.IsNullOrEmpty(notes))
                        {
                            lines.Add(notes);
                        }
                    }
                    System.IO.File.WriteAllLines(outOneFile, lines);
                    return(outOneFile);

                case "doc":
                case "docx":
                    using (var stream = new MemoryStream())
                    {
                        presentation.Save(stream, SaveFormat.Html);
                        stream.Flush();
                        stream.Seek(0, SeekOrigin.Begin);

                        var doc = new Words.Document(stream);
                        switch (format)
                        {
                        case "doc":
                            doc.Save(outOneFile, Words.SaveFormat.Doc);
                            break;

                        case "docx":
                            doc.Save(outOneFile, Words.SaveFormat.Docx);
                            break;

                        default:
                            throw new ArgumentException($"Unknown format {format}");
                        }
                    }
                    return(outOneFile);

                case "bmp":
                case "jpeg":
                case "png":
                case "emf":
                case "wmf":
                case "gif":
                case "exif":
                case "ico":
                    ImageFormat GetImageFormat(string f)
                    {
                        switch (format)
                        {
                        case "bmp":
                            return(ImageFormat.Bmp);

                        case "jpeg":
                            return(ImageFormat.Jpeg);

                        case "png":
                            return(ImageFormat.Png);

                        case "emf":
                            return(ImageFormat.Wmf);

                        case "wmf":
                            return(ImageFormat.Wmf);

                        case "gif":
                            return(ImageFormat.Gif);

                        case "exif":
                            return(ImageFormat.Emf);

                        case "ico":
                            return(ImageFormat.Icon);

                        default:
                            throw new ArgumentException($"Unknown format {format}");
                        }
                    }

                    ///var size = presentation.SlideSize.Size;

                    for (var i = 0; i < presentation.Slides.Count; i++)
                    {
                        var slide   = presentation.Slides[i];
                        var outFile = Path.Combine(outFolder, $"{i}.{format}");
                        using (var bitmap = slide.GetThumbnail(1, 1))                                // (new Size((int)size.Width, (int)size.Height)))
                            bitmap.Save(outFile, GetImageFormat(format));
                    }

                    return(null);

                case "svg":
                    var svgOptions = new SVGOptions
                    {
                        PicturesCompression = PicturesCompression.DocumentResolution
                    };

                    for (var i = 0; i < presentation.Slides.Count; i++)
                    {
                        var slide   = presentation.Slides[i];
                        var outFile = Path.Combine(outFolder, $"{i}.{format}");
                        using (var stream = new FileStream(outFile, FileMode.CreateNew))
                            slide.WriteAsSvg(stream, svgOptions);
                    }

                    return(null);

                default:
                    throw new ArgumentException($"Unknown format {format}");
                }
            }
        }
        private void SaveChunk(string outputDir, string chunkName, string fileName, ISlide[] chunkSlides, SlidesConversionFormat format, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (chunkSlides.Length == 0)
            {
                return;
            }
            cancellationToken.ThrowIfCancellationRequested();

            var presentation = chunkSlides[0].Presentation;

            switch (format)
            {
            case SlidesConversionFormat.pptx:
            case SlidesConversionFormat.pptm:
            case SlidesConversionFormat.ppsx:
            case SlidesConversionFormat.ppsm:
            case SlidesConversionFormat.potx:
            case SlidesConversionFormat.potm:
            case SlidesConversionFormat.pps:
            case SlidesConversionFormat.ppt:
            case SlidesConversionFormat.pot:
            case SlidesConversionFormat.odp:
            case SlidesConversionFormat.otp:

                using (var splitPresentation = new Presentation())
                {
                    while (splitPresentation.Slides.Count > 0)
                    {
                        splitPresentation.Slides.RemoveAt(0);
                    }

                    foreach (var slide in chunkSlides)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        splitPresentation.Slides.AddClone(slide);
                    }

                    splitPresentation.Save(Path.Combine(outputDir, $"{fileName}_{chunkName}.{format}"), format.ToString().ParseEnum <SaveFormat>());
                }
                break;

            case SlidesConversionFormat.pdf:
            case SlidesConversionFormat.xps:
            case SlidesConversionFormat.tiff:
            case SlidesConversionFormat.html:
            case SlidesConversionFormat.swf:

                presentation.Save(Path.Combine(outputDir, $"{fileName}_{chunkName}.{format}"),
                                  chunkSlides.Select(s => s.SlideNumber).ToArray(),
                                  format.ToString().ParseEnum <SaveFormat>());
                break;

            case SlidesConversionFormat.doc:
            case SlidesConversionFormat.docx:

                using (var stream = new MemoryStream())
                {
                    presentation.Save(stream, chunkSlides.Select(s => s.SlideNumber).ToArray(), SaveFormat.Html);
                    stream.Flush();
                    stream.Seek(0, SeekOrigin.Begin);

                    var doc        = new Words.Document(stream);
                    var wordFormat = format == SlidesConversionFormat.doc
                                                        ? Words.SaveFormat.Doc
                                                        : Words.SaveFormat.Docx;
                    doc.Save(Path.Combine(outputDir, $"{fileName}_{chunkName}.{format}"), wordFormat);
                }
                break;

            case SlidesConversionFormat.txt:

                var lines = new List <string>();
                foreach (var slide in chunkSlides)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    foreach (var shp in slide.Shapes)
                    {
                        if (shp is AutoShape ashp)
                        {
                            lines.Add(ashp.TextFrame.Text);
                        }
                    }

                    var notes = slide.NotesSlideManager.NotesSlide?.NotesTextFrame?.Text;

                    if (!string.IsNullOrEmpty(notes))
                    {
                        lines.Add(notes);
                    }
                }
                System.IO.File.WriteAllLines(Path.Combine(outputDir, $"{fileName}_{chunkName}.{format}"), lines);
                break;

            case SlidesConversionFormat.bmp:
            case SlidesConversionFormat.jpeg:
            case SlidesConversionFormat.png:
            case SlidesConversionFormat.emf:
            case SlidesConversionFormat.wmf:
            case SlidesConversionFormat.gif:
            case SlidesConversionFormat.exif:
            case SlidesConversionFormat.ico:

                foreach (var slide in chunkSlides)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var outFile = Path.Combine(outputDir, $"{fileName}_{slide.SlideNumber:D2}.{format}");
                    using (var bitmap = slide.GetThumbnail(1, 1))
                    {
                        bitmap.Save(outFile, GetImageFormat(format));
                    }
                }
                break;

            case SlidesConversionFormat.svg:

                var svgOptions = new SVGOptions
                {
                    PicturesCompression = PicturesCompression.DocumentResolution
                };
                foreach (var slide in chunkSlides)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var outFile = Path.Combine(outputDir, $"{fileName}_{slide.SlideNumber:D2}.{format}");
                    using (var stream = new FileStream(outFile, FileMode.CreateNew))
                    {
                        slide.WriteAsSvg(stream, svgOptions);
                    }
                }
                break;

            default:
                throw new ArgumentException($"Unknown format {format}");
            }
        }