Skip to content
Merged
Show file tree
Hide file tree
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
53 changes: 52 additions & 1 deletion File-Formats/DocIO/Working-with-Charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,57 @@ You can download a complete working sample from [GitHub](https://github.com/Sync

You can convert the chart in Word document as image using the [SaveAsImage](https://help.syncfusion.com/cr/file-formats/Syncfusion.OfficeChartToImageConverter.ChartToImageConverter.html#Syncfusion_OfficeChartToImageConverter_ChartToImageConverter_SaveAsImage_Syncfusion_OfficeChart_IOfficeChart_System_IO_Stream_) method in [ChartToImageConverter](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocIO.DLS.WordDocument.html#Syncfusion_DocIO_DLS_WordDocument_ChartToImageConverter).

To convert chart in Word document as an image, refer the below dependencies in your application.

<table>
<thead>
<tr>
<th width="20%">
Platform(s)
</th>
<th width="40%">
NuGets for Chart to Image
</th>
<th width="40%">
Assemblies for Chart to image
</th>
</tr>
</thead>
<tr>
<td>
Cross-platform, Xamarin
</td>
<td>
{{'[Word to PDF NuGets](https://help.syncfusion.com/file-formats/docio/nuget-packages-required#converting-word-document-to-pdf)' |  markdownify }}
</td>
<td>
{{'[Word to PDF assemblies](https://help.syncfusion.com/file-formats/docio/assemblies-required#converting-word-document-to-pdf)' |  markdownify }}
</td>
</tr>
<tr>
<td>
Windows-specific
</td>
<td>
{{'[Word to PDF NuGets](https://help.syncfusion.com/file-formats/docio/nuget-packages-required#converting-word-document-to-pdf)' |  markdownify }}<br/> {{'[Chart conversion NuGets](https://help.syncfusion.com/file-formats/docio/nuget-packages-required#converting-charts)' |  markdownify }}
</td>
<td>
{{'[Word to PDF assemblies](https://help.syncfusion.com/file-formats/docio/assemblies-required#converting-word-document-to-pdf)' |  markdownify }}<br/> {{'[Chart conversion assemblies](https://help.syncfusion.com/file-formats/docio/assemblies-required#converting-charts)' |  markdownify }}
</td>
</tr>
<tr>
<td>
UWP
</td>
<td>
{{'[Word to PDF NuGets of cross platform](https://help.syncfusion.com/file-formats/docio/nuget-packages-required#converting-word-document-to-pdf)' |  markdownify }}
</td>
<td>
{{'[Word to PDF assemblies of cross platform](https://help.syncfusion.com/file-formats/docio/assemblies-required#converting-word-document-to-pdf)' |  markdownify }}
</td>
</tr>
</table>

The following code example shows how to convert chart in the Word document as image.

{% tabs %}
Expand Down Expand Up @@ -938,7 +989,7 @@ using (Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResource
{% endhighlight %}

{% highlight c# tabtitle="UWP" %}
//DocIO supports chart to image conversion in Windows Forms, WPF, ASP.NET and ASP.NET MVC platform alone. You can convert chart as images in UWP using DocIORenderer.
// You can convert a chart to images in UWP using DocIORenderer, by using cross-platform NuGets or assemblies in a UWP application.
//Open the file as Stream.
using (Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.TemplateWithChart.docx"))
{
Expand Down
2 changes: 2 additions & 0 deletions File-Formats/Presentation/Assemblies-Required.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ Syncfusion.OfficeChart.NET<br/>Syncfusion.PresentationRenderer.NET<br/>Syncfusio
</tr>
</table>

## Converting Charts

The following assemblies are required to be referred in addition to the above mentioned assemblies for converting the chart present in the PowerPoint Presentation into PDF.
<table>
<tr>
Expand Down
123 changes: 123 additions & 0 deletions File-Formats/Presentation/Working-with-Charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,80 @@ You can download a complete working sample from [GitHub](https://github.com/Sync

## Chart to Image conversion

To convert chart in PowerPoint slide as an image, refer the below dependencies in your application.

<table>
<thead>
<tr>
<th width="20%">
Platform(s)
</th>
<th width="40%">
NuGets for Chart to Image
</th>
<th width="40%">
Assemblies for Chart to image
</th>
</tr>
</thead>
<tr>
<td>
Cross-platform, Xamarin
</td>
<td>
{{'[PPTX to PDF NuGets](https://help.syncfusion.com/file-formats/presentation/nuget-packages-required#converting-powerpoint-presentation-into-pdf)' |  markdownify }}
</td>
<td>
{{'[PPTX to PDF assemblies](https://help.syncfusion.com/file-formats/presentation/assemblies-required#converting-powerpoint-presentation-to-pdf)' |  markdownify }}
</td>
</tr>
<tr>
<td>
Windows-specific
</td>
<td>
{{'[PPTX to PDF NuGets](https://help.syncfusion.com/file-formats/presentation/nuget-packages-required#converting-powerpoint-presentation-into-pdf)' |  markdownify }}<br/> {{'[Chart conversion NuGets](https://help.syncfusion.com/file-formats/presentation/nuget-packages-required#converting-charts-in-presentation)' |  markdownify }}
</td>
<td>
{{'[PPTX to PDF assemblies](https://help.syncfusion.com/file-formats/presentation/assemblies-required#converting-powerpoint-presentation-to-pdf)' |  markdownify }}<br/> {{'[Chart conversion assemblies](https://help.syncfusion.com/file-formats/presentation/nuget-packages-required#converting-charts-in-presentation)' |  markdownify }}
</td>
</tr>
<tr>
<td>
UWP
</td>
<td>
{{'[PPTX to PDF NuGets of cross platform](https://help.syncfusion.com/file-formats/presentation/nuget-packages-required#converting-powerpoint-presentation-into-pdf)' |  markdownify }}
</td>
<td>
{{'[PPTX to PDF assemblies of cross platform](https://help.syncfusion.com/file-formats/presentation/assemblies-required#converting-powerpoint-presentation-to-pdf)' |  markdownify }}
</td>
</tr>
</table>

The following code example demonstrates how to convert the charts in a Presentation slide to image.

T> You can specify the quality of the converted charts by setting the scaling mode. For more details on how to set the scaling mode, see [Converting PowerPoint presentation to Images](/file-formats/presentation/getting-started#converting-powerpoint-presentation-to-images)

{% tabs %}

{% highlight c# tabtitle="C# [Cross-platform]" %}
//Loads or open an PowerPoint Presentation
FileStream inputStream = new FileStream("../../../Data/Sample.pptx", FileMode.Open);
IPresentation pptxDoc = Presentation.Open(inputStream);
//Initialize the PresentationRenderer
pptxDoc.PresentationRenderer = new PresentationRenderer();
//Gets the first instance of chart from slide
IPresentationChart chart = pptxDoc.Slides[0].Charts[0];
//Converts the chart to image.
Stream image = new FileStream("../../../Data/ChartToImage.jpg", FileMode.Create, FileAccess.ReadWrite);
pptxDoc.PresentationRenderer.ConvertToImage(chart, image);
//Closes the presentation
pptxDoc.Close();
image.Close();
inputStream.Close();
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
//Opens the Presentation
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
Expand Down Expand Up @@ -757,6 +825,61 @@ stream.Close()
pptxDoc.Close()
{% endhighlight %}

{% highlight c# tabtitle="UWP" %}
//You can convert a chart to images in UWP using PresentationRenderer, by using cross-platform NuGets or assemblies in a UWP application.
//Loads or open an PowerPoint Presentation
IPresentation pptxDoc = Presentation.Open(assembly.GetManifestResourceStream("Convert_chart_to_image.Assets.Template.pptx"));
//Initialize the PresentationRenderer
pptxDoc.PresentationRenderer = new PresentationRenderer();
//Gets the first instance of chart from slide
IPresentationChart chart = pptxDoc.Slides[0].Charts[0];
//Converts the chart to image.
//Creates a stream instance to store the image
MemoryStream stream = new MemoryStream();
pptxDoc.PresentationRenderer.ConvertToImage(chart, stream);
//Closes the presentation
pptxDoc.Close();
inputStream.Close();
//Save the memory stream as file.
Save(stream as MemoryStream, "ChartToImage.jpeg");
/// <summary>
/// Save the image.
/// </summary>
async void Save(MemoryStream streams, string filename)
{
streams.Position = 0;
StorageFile stFile;
if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")))
{
FileSavePicker savePicker = new FileSavePicker();
savePicker.DefaultFileExtension = ".jpeg";
savePicker.SuggestedFileName = filename;
savePicker.FileTypeChoices.Add("Image", new List<string>() { ".jpeg" });
stFile = await savePicker.PickSaveFileAsync();
}
else
{
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
}
if (stFile != null)
{
using (Windows.Storage.Streams.IRandomAccessStream zipStream = await stFile.OpenAsync(FileAccessMode.ReadWrite))
{
//Write compressed data from memory to file.
using (Stream outstream = zipStream.AsStreamForWrite())
{
byte[] buffer = streams.ToArray();
outstream.Write(buffer, 0, buffer.Length);
outstream.Flush();
}
}
}
//Launch the saved image file.
await Windows.System.Launcher.LaunchFileAsync(stFile);
}
{% endhighlight %}

{% endtabs %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PowerPoint-Examples/tree/master/Charts/Convert-chart-to-image).
Expand Down