-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from Venkateshmuruganandam/main
Sample added for Customize image path in Word to HTML
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...rsions/Customize-image-path-in-Word-to-html/.NET/Customize-image-path-in-Word-to-html.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.7.34031.279 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Customize-image-path-in-Word-to-html", "Customize-image-path-in-Word-to-html\Customize-image-path-in-Word-to-html.csproj", "{8C1A0AC2-F4DE-409E-B6E0-BC28228C528C}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{8C1A0AC2-F4DE-409E-B6E0-BC28228C528C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8C1A0AC2-F4DE-409E-B6E0-BC28228C528C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8C1A0AC2-F4DE-409E-B6E0-BC28228C528C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8C1A0AC2-F4DE-409E-B6E0-BC28228C528C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {8C795B5F-A830-4615-98C4-780853867A07} | ||
EndGlobalSection | ||
EndGlobal |
15 changes: 15 additions & 0 deletions
15
...tml/.NET/Customize-image-path-in-Word-to-html/Customize-image-path-in-Word-to-html.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Customize_image_path_in_Word_to_html</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file added
BIN
+75.9 KB
...mize-image-path-in-Word-to-html/.NET/Customize-image-path-in-Word-to-html/Data/Input.docx
Binary file not shown.
49 changes: 49 additions & 0 deletions
49
...Customize-image-path-in-Word-to-html/.NET/Customize-image-path-in-Word-to-html/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
| ||
using Syncfusion.DocIO; | ||
using Syncfusion.DocIO.DLS; | ||
|
||
|
||
namespace Customize_image_path_in_Word_to_html | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
//Open the file as a Stream. | ||
using (FileStream docStream = new FileStream(Path.GetFullPath(@"../../../Data/Input.docx"), FileMode.Open, FileAccess.Read)) | ||
{ | ||
//Load the file stream into a Word document. | ||
using (WordDocument document = new WordDocument(docStream, FormatType.Docx)) | ||
{ | ||
//Hook the event to customize the image. | ||
document.SaveOptions.ImageNodeVisited += SaveImage; | ||
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../WordToHTML.html"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) | ||
{ | ||
//Save the HTML file. | ||
document.Save(outputStream, FormatType.Html); | ||
} | ||
} | ||
} | ||
static void SaveImage(object sender, ImageNodeVisitedEventArgs args) | ||
{ | ||
// Specify the folder path. | ||
string folderPath = @"D:\Temp"; | ||
// Specify the image filename. | ||
string imageFilename = "Image.png"; | ||
// Check if the folder exists, and create it if it doesn't. | ||
if (!Directory.Exists(folderPath)) | ||
{ | ||
Directory.CreateDirectory(folderPath); | ||
} | ||
string imageFullPath = Path.Combine(folderPath, imageFilename); | ||
// Save the image stream as a file. | ||
using (FileStream fileStreamOutput = File.Create(imageFullPath)) | ||
{ | ||
args.ImageStream.CopyTo(fileStreamOutput); | ||
} | ||
// Set the URI to be used for the image in the output HTML. | ||
args.Uri = imageFullPath; | ||
} | ||
} | ||
} | ||
} |