In accordance with the requirements of the project, we need to convert images from a Word document into a bitmap object. To do this, we tried to convert the inlineshape object from the Microsoft.Office.Interop.Word file to bitmap. However, it was not possible to succeed by receiving the clipboard object as null. Please find the code we tried as shown below:
using System.Drawing;
using Microsoft.Office.Interop.Word;
namespace WordApp1
{
class Program
{
static void Main(string[] args)
{
Application wordApp = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
Documents documents = wordApp.Documents;
Document d = null;
foreach (Document document in documents)
{
if (document.ActiveWindow.Caption.Contains("{Word document name}"))
{
d = document;
}
}
foreach (InlineShape shape in d.InlineShapes)
{
shape.Range.Select();
d.ActiveWindow.Selection.Range.CopyAsPicture();
System.Windows.Forms.IDataObject dobj = System.Windows.Forms.Clipboard.GetDataObject();
if(dobj.GetDataPresent(typeof(System.Drawing.Bitmap)))
{
Bitmap bmp;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp = (Bitmap)dobj.GetData(typeof(System.Drawing.Bitmap));
}
}
}
}
}
Has anyone worked on converting word images to a bitmap? It would be very useful if you could direct us to how to continue the conversion of images from a text document into a raster image object.