diff --git a/File-Formats/Presentation/Presentation-to-image.md b/File-Formats/Presentation/Presentation-to-image.md index 55b7cee36..7c48ba563 100644 --- a/File-Formats/Presentation/Presentation-to-image.md +++ b/File-Formats/Presentation/Presentation-to-image.md @@ -118,6 +118,30 @@ The following code example demonstrates the conversion of an entire Presentation {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (FileStream fileStream = new FileStream("Sample.pptx", FileMode.Open, FileAccess.Read)) +{ + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(fileStream)) + { + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint to image as stream. + Stream[] images = pptxDoc.RenderAsImages(ExportImageFormat.Jpeg); + //Saves the images to file system + foreach (Stream stream in images) + { + //Create the output image file stream + using (FileStream fileStreamOutput = File.Create("Output" + Guid.NewGuid().ToString() + ".jpg")) + { + //Copy the converted image stream into created output stream + stream.CopyTo(fileStreamOutput); + } + } + } +} +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Loads the PowerPoint Presentation IPresentation pptxDoc = Presentation.Open("Sample.pptx"); @@ -471,6 +495,40 @@ The following code sample demonstrates how to set a substitute font for a missin {% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +//Load the PowerPoint presentation and convert to image +using (IPresentation pptxDoc = Presentation.Open("Sample.pptx")) +{ + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + // Initializes the 'SubstituteFont' event to set the replacement font + pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont; + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + { + //Create the output image file stream + using (FileStream fileStreamOutput = File.Create("Output.jpg")) + { + //Copy the converted image stream into created output stream + stream.CopyTo(fileStreamOutput); + } + } +} +/// +/// Sets the alternate font when a specified font is unavailable in the production environment +/// +/// FontSettings type of the Presentation in which the specified font is used but unavailable in production environment. +/// Retrieves the unavailable font name and receives the substitute font name for conversion. +private static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args) +{ + if (args.OriginalFontName == "Arial Unicode MS") + + args.AlternateFontName = "Arial"; + else + args.AlternateFontName = "Times New Roman"; +} +{% endhighlight %} + {% highlight c# tabtitle="C# [Windows-specific]" %} //Load the PowerPoint presentation and convert to image using (IPresentation pptxDoc = Presentation.Open("Sample.pptx"))