A preview image of the 1st page of a .doc or .docx document can easily be created with a tool called Free Spire.Doc for .NET (a totally free word API for commercial and personal use). I found it to be fast and accurate.
Note from the developer's page:
"The featured function, conversion allows converting Word documents (Word 97-2003, Word 2007, Word 2010, Word 2013, Word 2016 and Word 2019) to commonly used file format, such as XML, RTF, TXT, PDF, XPS, EPUB, HTML and Image etc.
Friendly Reminder:
Free version is limited to 500 paragraphs and 25 tables... "
This C# code creates a System.Drawing.Image object of the 1st page of a .docx file:
using Spire.Doc
byte[] docContent = File.ReadAllBytes(@"C:\Temp\word_document.docx");
using (MemoryStream ms = new MemoryStream(docContent))
{
// Creates a Spire.Doc object to work with
Spire.Doc.Document doc = new Spire.Doc.Document(ms, Spire.Doc.FileFormat.Auto);
// SaveToImages creates an array of System.Drawing.Image, we take only the 1st element
System.Drawing.Image img = doc.SaveToImages(0, 1, Spire.Doc.Documents.ImageType.Bitmap)[0];
}
To create the thumbnail image, the following C# example includes a second using block to do it, and then converts to a base64 string:
using Spire.Doc
byte[] docContent = File.ReadAllBytes(@"C:\Temp\word_document.docx");
using (MemoryStream ms = new MemoryStream(docContent))
{
// Creates a Spire.Doc object to work with
Spire.Doc.Document doc = new Spire.Doc.Document(ms, Spire.Doc.FileFormat.Auto);
// SaveToImages creates an array of System.Drawing.Image, we take only the 1st element
System.Drawing.Image img = doc.SaveToImages(0, 1, Spire.Doc.Documents.ImageType.Bitmap)[0];
using (var ms2 = new MemoryStream())
{
// Auxiliary object needed for GetThumbnailImage
System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
// We create a thumbnail (0.5 width and height = 50%)
img.GetThumbnailImage((int)(img.Width * 0.5), (int)(img.Height * 0.5), myCallback, IntPtr.Zero).Save(ms2, System.Drawing.Imaging.ImageFormat.Png);
// Convert to Base64 string representation of the image
return Convert.ToBase64String(ms2.ToArray());
}
}
In addition, the library can also convert in other ways, for instance this function returns .SVG files with each page:
doc.SaveToFile("resulting_file_name.svg", Spire.Doc.FileFormat.SVG);