Skip to content

Commit a869164

Browse files
Modified the input document
1 parent 35bad83 commit a869164

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed
Binary file not shown.
Binary file not shown.

Markdown-to-Word-conversion/Modify-image-size/Modify-image-size/Data/Input.md

Lines changed: 19 additions & 6 deletions
Large diffs are not rendered by default.

Markdown-to-Word-conversion/Modify-image-size/Modify-image-size/Modify-image-size.csproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<None Update="Data\Adventure-work-cycles.png">
15+
<None Update="Data\Input.md">
1616
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1717
</None>
18-
<None Update="Data\Cycle.png">
19-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20-
</None>
21-
<None Update="Data\Image_1.png">
22-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
23-
</None>
24-
<None Update="Data\Image_2.png">
18+
<None Update="Data\Road-550.png">
2519
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2620
</None>
2721
<None Update="Output\.gitkeep">

Markdown-to-Word-conversion/Modify-image-size/Modify-image-size/Program.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,53 @@
22
using Syncfusion.DocIO;
33
using System.Net;
44

5+
//Register Syncfusion license
6+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc=");
7+
58
using (WordDocument document = new WordDocument())
69
{
7-
// Register the event to customize images while importing Markdown.
10+
// Register an event to customize images while importing Markdown.
811
document.MdImportSettings.ImageNodeVisited += MdImportSettings_ImageNodeVisited;
9-
// Open the input Markdown file for reading.
10-
using (FileStream inputFileStream = new FileStream(@"Data/Input.md", FileMode.Open, FileAccess.Read))
12+
// Open the input Markdown file.
13+
using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.md"), FileMode.Open, FileAccess.Read))
1114
{
15+
// Load the Markdown file into the Word document.
1216
document.Open(inputFileStream, FormatType.Markdown);
13-
#region ImageResize
14-
// Find all images with the alternative text "File" and resize them to 300x300.
15-
List<Entity> pictures = document.FindAllItemsByProperty(EntityType.Picture, "AlternativeText", "Adventure");
17+
18+
// Find all images with the alternative text "Mountain" and resize them.
19+
List<Entity> pictures = document.FindAllItemsByProperty(EntityType.Picture, "AlternativeText", "Mountain");
1620
foreach (WPicture picture in pictures)
1721
{
18-
picture.Height = 300;
19-
picture.Width = 300;
22+
picture.Height = 250;
23+
picture.Width = 250;
2024
}
21-
#endregion
25+
2226
// Save the modified document.
23-
using (FileStream outputFileStream = new FileStream(@"Output/Result.docx", FileMode.Create, FileAccess.Write))
27+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write))
2428
{
2529
document.Save(outputFileStream, FormatType.Docx);
2630
}
2731
}
2832
}
2933

34+
/// <summary>
35+
/// Customizes image loading from local and remote sources during Markdown import.
36+
/// </summary>
3037
static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs args)
3138
{
32-
// Set the image stream based on the image name from the Markdown input.
33-
if (args.Uri == "Image_1.png")
34-
args.ImageStream = new FileStream(@"Data/Image_1.png", FileMode.Open);
35-
else if (args.Uri == "Image_2.png")
36-
args.ImageStream = new FileStream(@"Data/Image_2.png", FileMode.Open);
37-
// If the image is from a URL, download and set it as a stream.
39+
// Load a specific image from a local path if the image URI matches.
40+
if (args.Uri == "Road-550.png")
41+
args.ImageStream = new FileStream(Path.GetFullPath(@"Data/Road-550.png"), FileMode.Open);
42+
// If the image URI starts with "https://", download and set the image from the URL.
3843
else if (args.Uri.StartsWith("https://"))
3944
{
40-
// Create a WebClient instance.
45+
// Initialize a WebClient instance for downloading.
4146
WebClient client = new WebClient();
42-
// Download the image as byte data.
47+
// Download the image data as a byte array.
4348
byte[] image = client.DownloadData(args.Uri);
44-
// Convert byte data to a memory stream.
49+
// Convert the byte array to a memory stream.
4550
Stream stream = new MemoryStream(image);
46-
// Set the stream for the image in Markdown.
51+
// Set the downloaded stream as the image in the Markdown.
4752
args.ImageStream = stream;
4853
}
4954
}

0 commit comments

Comments
 (0)