Skip to content

Commit eb200ba

Browse files
Merge pull request #438 from SyncfusionExamples/ES-262902-Extract-charts-as-images
ES-262902- Add the sample Extract-charts-as-images
2 parents 4d98c08 + 6c1f71e commit eb200ba

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Extract-charts-as-images", "Extract-charts-as-images\Extract-charts-as-images.csproj", "{5B0540C8-1A4D-4BB4-A0B9-10028D140E00}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{5B0540C8-1A4D-4BB4-A0B9-10028D140E00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5B0540C8-1A4D-4BB4-A0B9-10028D140E00}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5B0540C8-1A4D-4BB4-A0B9-10028D140E00}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5B0540C8-1A4D-4BB4-A0B9-10028D140E00}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Extract_charts_as_images</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIORenderer;
3+
4+
// Load the Word document.
5+
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Template.docx")))
6+
{
7+
// Find all chart elements in the Word document by EntityType.
8+
List<Entity> charts = document.FindAllItemsByProperty(EntityType.Chart, null, null);
9+
10+
// Create an instance of DocIORenderer.
11+
using (DocIORenderer renderer = new DocIORenderer())
12+
{
13+
// Loop through each chart found in the document.
14+
for (int i = 0; i < charts.Count; i++)
15+
{
16+
WChart chart = charts[i] as WChart;
17+
18+
// Convert the chart to an image stream.
19+
using (Stream stream = chart.SaveAsImage())
20+
{
21+
// Create a file stream to save the image to disk.
22+
using (FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/Chart" + i + ".jpeg")))
23+
{
24+
// Copy the image stream to the output file.
25+
stream.CopyTo(fileStreamOutput);
26+
}
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)