Skip to content

Instantly share code, notes, and snippets.

How to Extract Images from Word Document in C#. For more information, please follow link: https://kb.conholdate.com/total/net/how-to-extract-images-from-word-document-in-csharp
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using GroupDocs.Parser;
using GroupDocs.Parser.Data;
namespace ExtractImagesFromWordDocumentInCSharp
{
class Program
{
public static void Main(string[] args) // Main function to extract images from word using C#
{
// Remove the watermark in output
string licensePath = "/path/to/GroupDocs.Parser.lic";
GroupDocs.Parser.License lic = new GroupDocs.Parser.License();
lic.SetLicense(licensePath);
// Create an instance of Parser class
using (Parser parser = new Parser("/path/to/sample.docx"))
{
// Extract images
IEnumerable<PageImageArea> images = parser.GetImages();
// Check if images extraction is supported
if (images == null)
{
Console.WriteLine("Images extraction isn't supported");
return;
}
// Iterate over images
foreach (PageImageArea image in images)
{
// Print a page index, rectangle and image type:
Console.WriteLine(string.Format("Page: {0}, R: {1}, Type: {2}", image.Page.Index, image.Rectangle, image.FileType));
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment