Images play an important role to illustrate the key information in Word documents. Moreover, they make the document more attractive and improve its presentation. As a programmer, you may get a job to extract the images embedded within the Word DOCX or DOC documents. To achieve that, this article covers how to extract images from Word documents programmatically using C#. Moreover, you will see how to save the extracted images to the desired location.
C# API to Extract Images from Word Documents
To extract images from MS Word DOCX/DOC documents, we will use Aspose.Words for .NET. It is a powerful and widely used API for creating and manipulating Word documents. You can download the API’s DLL and add its reference to your application. Also, you can install it directly from NuGet using the package manager console.
PM> Install-Package Aspose.Words
Extract Images from a Word Document in C#
In Word documents, images are represented as shapes. Therefore, to extract images, you will have to process all the shapes in the document. The following are the steps to extract images from a Word DOCX document programmatically in C#.
- Load the Word file using Document class.
- Get all the shapes which have images into an IEnumerable object using Document.GetChildNodes(NodeType.Shape, Boolean) method.
- Loop through the retreieved shapes.
- In each iteration, extract the image and save it using Shape.ImageData.Save(string) method.
The following code sample shows how to extract images from a Word document in C#.
Try Aspose.Words for .NET for Free
You can get a free temporary license to try Aspose.Words for .NET without any limitations. Get your temporary license now.
Conclusion
Images have become an integral part of Word documents, which make the content more attractive. Therefore, Aspose.Words for .NET provides a wide range of features to add or manipulate images in Word documents.
This article particularly covered the extraction of images from Word documents. With the help of a code sample, you have learned how to extract each image in a Word DOCX/DOC file programmatically using C#. Moreover, you have seen how to save the extracted images to your desired location. You can read more about Aspose.Words for .NET using the documentation. In case you would have any questions, feel free to let us know via our forum.
See Also
Tip: If you ever need to get a Word document from a PowerPoint presentation, you can use Aspose Presentation to Word Document converter.