I am trying to convert DOCX file to HTML using Open XML power tools in .Net Core Project. Everything was smooth until i encounter images in the document file. I tried the below code for exporting the images using open XML power tools
using (WordprocessingDocument wDoc =
WordprocessingDocument.Open(memoryStream, true))
{
WmlToHtmlConverterSettings settings = new WmlToHtmlConverterSettings()
{
ImageHandler = imageInfo =>
{
imageInfo.Bitmap.Save([...]);
ImageFormat format = imageInfo.Bitmap.RawFormat;
}
}
XElement htmlElement = WmlToHtmlConverter.ConvertToHtml(wDoc, settings);
}
when I use imageInfo.Bitmap.Save(ms, imageFormat);' in the ImageHandler. I did try to add the System.Drawing.Common package from nuget, but that did not resolve the error.
Your stripped down sample should work. You maybe watch an issue of resolving system.drawing.common. Check your build output, mine shows
This code works with .net core 3.1 on windows and its behavior will differ depending on your used target/os:
Think about switching to some fork of OpenXmlPowerTools that supports .net > 4.x and OS beside of Windows.