Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions File-Formats/Presentation/Presentation-to-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
/// <summary>
/// Sets the alternate font when a specified font is unavailable in the production environment
/// </summary>
/// <param name="sender">FontSettings type of the Presentation in which the specified font is used but unavailable in production environment. </param>
/// <param name="args">Retrieves the unavailable font name and receives the substitute font name for conversion. </param>
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"))
Expand Down