Skip to content
Open
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
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36908.2 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert_EMF-images_to_PNG_in_Word-document", "Convert_EMF-images_to_PNG_in_Word-document\Convert_EMF-images_to_PNG_in_Word-document.csproj", "{0FB638DB-2793-4FB6-B1B3-18F786EA8EF5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0FB638DB-2793-4FB6-B1B3-18F786EA8EF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FB638DB-2793-4FB6-B1B3-18F786EA8EF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FB638DB-2793-4FB6-B1B3-18F786EA8EF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FB638DB-2793-4FB6-B1B3-18F786EA8EF5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3AC4FA9F-473F-4350-B422-A0C4691A8EA6}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Convert_EMF_images_to_PNG_in_Word_document</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
<PackageReference Include="Syncfusion.MetafileRenderer.Net.Core" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="Data\Input.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using SkiaSharp;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.Drawing;
using Syncfusion.Metafile;



using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.docx", FileMode.Open, FileAccess.ReadWrite))
{
// Opens an input Word template.
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
// Find all picture in the document.
List<Entity> images = document.FindAllItemsByProperty(EntityType.Picture, null, null);
// Iterate through each image in the document.
foreach (Entity entity in images)
{
WPicture picture = entity as WPicture;
float width = picture.Width;
float height = picture.Height;

// Convert the image bytes into a memory stream.
MemoryStream stream = new MemoryStream(picture.ImageBytes);
// Create an Image object from the memory stream.
Image image = Image.FromStream(stream);
// Check if the image format is EMF.
if (image.RawFormat.Equals(ImageFormat.Emf))
{
MemoryStream imageByteStream = new MemoryStream(picture.ImageBytes);
//Create a new instance for the MetafileRenderer
MetafileRenderer renderer = new MetafileRenderer();
//Convert the Metafile to SKBitmap Image.
SKBitmap skBitmap = renderer.ConvertToImage(imageByteStream);
//Save the image as stream
using (SKImage skImage = SKImage.FromBitmap(skBitmap))
using (SKData data = skImage.Encode(SKEncodedImageFormat.Png, 100))

using (MemoryStream pngStream = new MemoryStream())
{
data.SaveTo(pngStream);
pngStream.Position = 0;
picture.LoadImage(pngStream);
picture.Height = height;
picture.Width = width;
}
}
}
// Save the modified document to the specified output file.
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.html"), FileMode.Create, FileAccess.Write))
{
document.Save(outputStream, FormatType.Html);
}
}
}


Loading