Skip to content

Commit 9b0d7c0

Browse files
Modified the XML comments
1 parent a869164 commit 9b0d7c0

File tree

1 file changed

+10
-20
lines changed
  • Markdown-to-Word-conversion/Modify-image-size/Modify-image-size

1 file changed

+10
-20
lines changed

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

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

5-
//Register Syncfusion license
6-
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc=");
7-
5+
// Create a Word document instance.
86
using (WordDocument document = new WordDocument())
97
{
10-
// Register an event to customize images while importing Markdown.
8+
// Hook the event to customize the image while importing Markdown.
119
document.MdImportSettings.ImageNodeVisited += MdImportSettings_ImageNodeVisited;
12-
// Open the input Markdown file.
1310
using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.md"), FileMode.Open, FileAccess.Read))
1411
{
15-
// Load the Markdown file into the Word document.
12+
// Open the input Markdown file.
1613
document.Open(inputFileStream, FormatType.Markdown);
17-
1814
// Find all images with the alternative text "Mountain" and resize them.
19-
List<Entity> pictures = document.FindAllItemsByProperty(EntityType.Picture, "AlternativeText", "Mountain");
20-
foreach (WPicture picture in pictures)
21-
{
22-
picture.Height = 250;
23-
picture.Width = 250;
24-
}
25-
15+
WPicture picture = document.FindItemByProperty(EntityType.Picture, "AlternativeText", "Mountain") as WPicture;
16+
picture.Height = 250;
17+
picture.Width = 250;
2618
// Save the modified document.
2719
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write))
2820
{
@@ -36,19 +28,17 @@
3628
/// </summary>
3729
static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs args)
3830
{
39-
// Load a specific image from a local path if the image URI matches.
31+
// Set the image stream based on the image name from the input Markdown.
4032
if (args.Uri == "Road-550.png")
4133
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.
34+
// Retrieve the image from the website and use it.
4335
else if (args.Uri.StartsWith("https://"))
4436
{
45-
// Initialize a WebClient instance for downloading.
4637
WebClient client = new WebClient();
47-
// Download the image data as a byte array.
38+
// Download the image as a stream.
4839
byte[] image = client.DownloadData(args.Uri);
49-
// Convert the byte array to a memory stream.
5040
Stream stream = new MemoryStream(image);
51-
// Set the downloaded stream as the image in the Markdown.
41+
// Set the retrieved image from the input Markdown.
5242
args.ImageStream = stream;
5343
}
5444
}

0 commit comments

Comments
 (0)