Skip to content

Commit 6bd2098

Browse files
Merge pull request #259 from VijayadharshiniMathiyalagan/ES-876655-How-to-change-the-image-size-during-Markdown-to-Word-conversion
Added the sample for change the image size during markdown to word conversion
2 parents 9f071da + 1864de2 commit 6bd2098

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35309.182
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modify-image-size", "Modify-image-size\Modify-image-size.csproj", "{280B67DF-9185-42E5-9498-D12BAC8BAE2F}"
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+
{280B67DF-9185-42E5-9498-D12BAC8BAE2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{280B67DF-9185-42E5-9498-D12BAC8BAE2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{280B67DF-9185-42E5-9498-D12BAC8BAE2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{280B67DF-9185-42E5-9498-D12BAC8BAE2F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {BF05181A-BA9E-449A-9395-3A211A69123B}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# **Product Overview of Adventure Works Cycles**
2+
3+
4+
## **Mountain\-200**
5+
6+
![Road](Road-550.png)
7+
8+
9+
10+
**Size:** 38
11+
12+
**Price:** $2,294.99
13+
14+
15+
## **Mountain\-300**
16+
17+
![Mountain](https://www.syncfusion.com/downloads/support/directtrac/general/Mountain-300-989274178.png)
18+
19+
20+
21+
**Size:** 35
22+
23+
**Price:** $1,079.99
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.DocIO.NET" Version="*" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<None Update="Data\Input.md">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
<None Update="Data\Road-550.png">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
<None Update="Output\.gitkeep">
22+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
23+
</None>
24+
</ItemGroup>
25+
26+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
using System.Net;
4+
5+
using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.md"), FileMode.Open, FileAccess.Read))
6+
{
7+
// Create a Word document instance.
8+
using (WordDocument document = new WordDocument())
9+
{
10+
// Hook the event to customize the image while importing Markdown.
11+
document.MdImportSettings.ImageNodeVisited += MdImportSettings_ImageNodeVisited;
12+
// Open the input Markdown file.
13+
document.Open(inputFileStream, FormatType.Markdown);
14+
// Find a picture by its alternative text and resize it.
15+
WPicture picture = document.FindItemByProperty(EntityType.Picture, "AlternativeText", "Mountain") as WPicture;
16+
picture.Height = 250;
17+
picture.Width = 250;
18+
// Save the modified document.
19+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write))
20+
{
21+
document.Save(outputFileStream, FormatType.Docx);
22+
}
23+
}
24+
}
25+
26+
/// <summary>
27+
/// Customizes image loading from local and remote sources during Markdown import.
28+
/// </summary>
29+
static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs args)
30+
{
31+
// Set the image stream based on the image name from the input Markdown.
32+
if (args.Uri == "Road-550.png")
33+
args.ImageStream = new FileStream(Path.GetFullPath(@"Data/Road-550.png"), FileMode.Open);
34+
// Retrieve the image from the website and use it.
35+
else if (args.Uri.StartsWith("https://"))
36+
{
37+
WebClient client = new WebClient();
38+
// Download the image as a stream.
39+
byte[] image = client.DownloadData(args.Uri);
40+
Stream stream = new MemoryStream(image);
41+
// Set the retrieved image from the input Markdown.
42+
args.ImageStream = stream;
43+
}
44+
}

0 commit comments

Comments
 (0)