Skip to content

Commit

Permalink
Merge pull request #138 from Venkateshmuruganandam/main
Browse files Browse the repository at this point in the history
Sample added for Customize image path in Word to HTML
  • Loading branch information
MohanaselvamJothi authored Oct 23, 2023
2 parents cf9e0dd + bbe0ad3 commit 5816db5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
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
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 not shown.
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;
}
}
}
}

0 comments on commit 5816db5

Please sign in to comment.