Skip to content

Commit 9b61ac1

Browse files
Updated GitHub Examples for Word
1 parent 9f75e75 commit 9b61ac1

7 files changed

Lines changed: 32 additions & 34 deletions

File tree

  • HTML-conversions/Customize-image-data/.NET/Customize-image-data
  • Markdown-to-Word-conversion
  • Word-document/Extract-Text-From-Word-Document/.NET/Extract-Text-From-Word-Document
  • Word-to-Image-conversion/Use-alternate-font-without-installing/.NET/Use-alternate-font-without-installing
  • Word-to-PDF-Conversion
    • Convert-Word-document-to-PDF/Docker/Alpine/WordToPDFDockerSample
    • Use-alternate-font-without-installing/.NET/Use-alternate-font-without-installing

HTML-conversions/Customize-image-data/.NET/Customize-image-data/Program.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,20 @@ namespace Customize_image_data
77
class Program
88
{
99
static void Main(string[] args)
10-
{
11-
//Loads an existing Word document into DocIO instance.
12-
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.html"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
10+
{
11+
//Creates a new instance of WordDocument
12+
using (WordDocument document = new WordDocument())
1313
{
14-
using (WordDocument document = new WordDocument())
15-
{
16-
//Hooks the ImageNodeVisited event to open the image from a specific location.
17-
document.HTMLImportSettings.ImageNodeVisited += OpenImage;
18-
//Opens the input HTML document.
19-
document.Open(fileStreamPath, FormatType.Html);
20-
//Unhooks the ImageNodeVisited event after loading HTML.
21-
document.HTMLImportSettings.ImageNodeVisited -= OpenImage;
22-
//Creates file stream.
23-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/HtmlToWord.docx"), FileMode.Create, FileAccess.ReadWrite))
24-
{
25-
//Saves the Word document to file stream.
26-
document.Save(outputFileStream, FormatType.Docx);
27-
}
28-
}
14+
//Hooks the ImageNodeVisited event to open the image from a specific location
15+
document.HTMLImportSettings.ImageNodeVisited += OpenImage;
16+
//Opens the input HTML document
17+
document.Open(@"Data\Input.html", FormatType.Html);
18+
//Unhooks the ImageNodeVisited event after loading HTML
19+
document.HTMLImportSettings.ImageNodeVisited -= OpenImage;
20+
//Saves the Word document
21+
document.Save(@"Output\HtmlToWord.docx", FormatType.Docx);
22+
//Closes the WordDocument instance
23+
document.Close();
2924
}
3025
}
3126
private static void OpenImage(object sender, ImageNodeVisitedEventArgs args)
@@ -34,4 +29,5 @@ private static void OpenImage(object sender, ImageNodeVisitedEventArgs args)
3429
args.ImageStream = System.IO.File.OpenRead(args.Uri);
3530
}
3631
}
32+
3733
}

Markdown-to-Word-conversion/Customize-image/.NET/Customize-image/Program.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Syncfusion.Drawing;
44
using System.IO;
55
using System.Net;
6+
using System.Net.Http;
67

78
namespace Customize_image
89
{
@@ -31,12 +32,12 @@ private static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.
3132
//Retrive the image from the website and use it.
3233
else if (args.Uri.StartsWith("https://"))
3334
{
34-
WebClient client = new WebClient();
3535
//Download the image as a stream.
36-
byte[] image = client.DownloadData(args.Uri);
37-
Stream stream = new MemoryStream(image);
38-
//Set the retrieved image from the input Markdown.
39-
args.ImageStream = stream;
36+
using (HttpClient client = new HttpClient())
37+
{
38+
byte[] image = client.GetByteArrayAsync(args.Uri).GetAwaiter().GetResult();
39+
args.ImageStream = new MemoryStream(image);
40+
}
4041
}
4142
}
4243
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.Office.M
3434
// Retrieve the image from the website and use it.
3535
else if (args.Uri.StartsWith("https://"))
3636
{
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;
37+
using (HttpClient client = new HttpClient())
38+
{
39+
byte[] image = client.GetByteArrayAsync(args.Uri).GetAwaiter().GetResult();
40+
args.ImageStream = new MemoryStream(image);
41+
}
4342
}
4443
}

Word-document/Extract-Text-From-Word-Document/.NET/Extract-Text-From-Word-Document/Extract-Text-From-Word-Document.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
<None Update="Data\Template.docx">
1515
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1616
</None>
17-
<None Update="Output\.gitkeep">
17+
<None Update="Output\.gitkeep">
1818
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1919
</None>
20+
<None Update="Output/Output.txt">
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
</None>
2023
</ItemGroup>
2124

2225
</Project>

Word-to-Image-conversion/Use-alternate-font-without-installing/.NET/Use-alternate-font-without-installing/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void Main(string[] args)
4242
private static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
4343
{
4444
//Sets the alternate font when a specified font is not installed in the production environment.
45-
if (args.OrignalFontName == "Arial Unicode MS")
45+
if (args.OriginalFontName == "Arial Unicode MS")
4646
{
4747
switch (args.FontStyle)
4848
{

Word-to-PDF-Conversion/Convert-Word-document-to-PDF/Docker/Alpine/WordToPDFDockerSample/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
22

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

87
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build

Word-to-PDF-Conversion/Use-alternate-font-without-installing/.NET/Use-alternate-font-without-installing/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void Main(string[] args)
3838
private static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
3939
{
4040
//Sets the alternate font when a specified font is not installed in the production environment.
41-
if (args.OrignalFontName == "Arial Unicode MS")
41+
if (args.OriginalFontName == "Arial Unicode MS")
4242
{
4343
switch (args.FontStyle)
4444
{

0 commit comments

Comments
 (0)