Hi all,
How I can to extract the images from Word file. I am using this code snippet below but it doesn't work for me.
I would like to save my images to specific folder which will be choosen by user. So, how can I modify bolded line
to do that? When I replace imageName variable with variable which contain folder path the compiler pop up error at that line.
Guys, thanks a lot on your time
//Load document
Document document = new Document(@"E:\Work\Documents\WordDocuments\Spire.Doc for .NET.docx");
int index = 0;
//Get Each Section of Document
foreach (Section section in document.Sections)
{
//Get Each Paragraph of Section
foreach (Paragraph paragraph in section.Paragraphs)
{
//Get Each Document Object of Paragraph Items
foreach (DocumentObject docObject in paragraph.ChildObjects)
{
//If Type of Document Object is Picture, Extract.
if (docObject.DocumentObjectType == DocumentObjectType.Picture)
{
DocPicture picture = docObject as DocPicture;
//Name Image
String imageName = String.Format(@"images\Image-{0}.png", index);
//Save Image
picture.Image.Save(imageName, System.Drawing.Imaging.ImageFormat.Png);
index++;
}
}
}
}