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
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@ namespace Customize_image_data
class Program
{
static void Main(string[] args)
{
//Loads an existing Word document into DocIO instance.
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.html"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Creates a new instance of WordDocument
using (WordDocument document = new WordDocument())
{
using (WordDocument document = new WordDocument())
{
//Hooks the ImageNodeVisited event to open the image from a specific location.
document.HTMLImportSettings.ImageNodeVisited += OpenImage;
//Opens the input HTML document.
document.Open(fileStreamPath, FormatType.Html);
//Unhooks the ImageNodeVisited event after loading HTML.
document.HTMLImportSettings.ImageNodeVisited -= OpenImage;
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/HtmlToWord.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
document.Save(outputFileStream, FormatType.Docx);
}
}
//Hooks the ImageNodeVisited event to open the image from a specific location
document.HTMLImportSettings.ImageNodeVisited += OpenImage;
//Opens the input HTML document
document.Open(@"Data\Input.html", FormatType.Html);
//Unhooks the ImageNodeVisited event after loading HTML
document.HTMLImportSettings.ImageNodeVisited -= OpenImage;
//Saves the Word document
document.Save(@"Output\HtmlToWord.docx", FormatType.Docx);
//Closes the WordDocument instance
document.Close();
}
}
private static void OpenImage(object sender, ImageNodeVisitedEventArgs args)
Expand All @@ -34,4 +29,5 @@ private static void OpenImage(object sender, ImageNodeVisitedEventArgs args)
args.ImageStream = System.IO.File.OpenRead(args.Uri);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Syncfusion.Drawing;
using System.IO;
using System.Net;
using System.Net.Http;

namespace Customize_image
{
Expand Down Expand Up @@ -31,12 +32,12 @@ private static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.
//Retrive the image from the website and use it.
else if (args.Uri.StartsWith("https://"))
{
WebClient client = new WebClient();
//Download the image as a stream.
byte[] image = client.DownloadData(args.Uri);
Stream stream = new MemoryStream(image);
//Set the retrieved image from the input Markdown.
args.ImageStream = stream;
using (HttpClient client = new HttpClient())
{
byte[] image = client.GetByteArrayAsync(args.Uri).GetAwaiter().GetResult();
args.ImageStream = new MemoryStream(image);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.Office.M
// Retrieve the image from the website and use it.
else if (args.Uri.StartsWith("https://"))
{
WebClient client = new WebClient();
// Download the image as a stream.
byte[] image = client.DownloadData(args.Uri);
Stream stream = new MemoryStream(image);
// Set the retrieved image from the input Markdown.
args.ImageStream = stream;
using (HttpClient client = new HttpClient())
{
byte[] image = client.GetByteArrayAsync(args.Uri).GetAwaiter().GetResult();
args.ImageStream = new MemoryStream(image);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output/Output.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void Main(string[] args)
private static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
{
//Sets the alternate font when a specified font is not installed in the production environment.
if (args.OrignalFontName == "Arial Unicode MS")
if (args.OriginalFontName == "Arial Unicode MS")
{
switch (args.FontStyle)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
RUN apk update && apk upgrade && apk add fontconfig
RUN apk add --update ttf-dejavu fontconfig
RUN apk update && apk add --no-cache fontconfig ttf-dejavu
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void Main(string[] args)
private static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
{
//Sets the alternate font when a specified font is not installed in the production environment.
if (args.OrignalFontName == "Arial Unicode MS")
if (args.OriginalFontName == "Arial Unicode MS")
{
switch (args.FontStyle)
{
Expand Down
Loading