We help IT Professionals succeed at work.

how to extract images from word document with same quality and size ?

Last Modified: 2017-04-02

I am trying to export all the images in a generated word document...
I wound some code on the net such as this one:
For Each i As Word.InlineShape In mWordDocument.InlineShapes
            Dim bmp As Image = Clipboard.GetImage()
            If bmp IsNot Nothing Then
                If bmp.Size.Width > MINIMUM_BITMAP_WIDTH Then
                    mMapNoImage.Add(iNO, bmp)
                    iNO += 1
                End If
            End If

This works somewhat... but the quality of the image if not adequate.
Also sometime it only gets part of the image!
Further whereas in the word document I can resize the image and it keeps its clarity, the images exported has poor resolution.

How can I extract all the images and have a jog file with same quality as tat of the object embedded within the word document ???

Thanks for any hints
Watch Question

RaminTechnical Advisor

Word documents containing embedded images can not be easily extracted. Attempts to copy and paste the images result in poor quality images.

Try these methods,

save the document as a web page using the following steps:
1. On the File menu click Save as Web Page
2. In the Save As drop down select Web Page (*.htm; *.html)
Images will be extracted from the document and placed in the folder named <DocumentName>_files in the same location as the saved web page.


I have been told that there is a way to improve bitmap quality by using windows metafile format and raw bits directly from word.
I'll play with this and if indeed successful, I'll post the solution here (thus answering my own question)



indeed they were right those who suggested metafile!

It works perfectly and the images taken from the word document are as good as when they are in the doc!

Here is the code fI come up with:
Private Sub ExtractImage()
        Dim iNO As Integer = 1
        Dim vData() As Byte
        Dim NewGraphic As Graphics = Nothing

        For Each i As Word.InlineShape In mWordDocument.InlineShapes
            vData = i.Range.EnhMetaFileBits
            Using mem As New IO.MemoryStream(vData)
                Using mf As New Imaging.Metafile(mem)
                    If mf.Width > MINIMUM_BITMAP_WIDTH Then
                        Using bmp As New Bitmap(mf.Width, mf.Height)
                            NewGraphic = Graphics.FromImage(bmp)
                            NewGraphic.FillRectangle(New SolidBrush(Color.White), 0, 0, mf.Width, mf.Height)
                            NewGraphic.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
                            NewGraphic.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
                            NewGraphic.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
                            NewGraphic.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
                            NewGraphic.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit

                            NewGraphic.DrawImage(mf, 0, 0, mf.Width, mf.Height)
#If DEBUG Then
                            bmp.Save(String.Format("d:\temp\x1_{0}.jpg", iNO.ToString("000")), Imaging.ImageFormat.Jpeg)
#End If
                            mMapNoImage.Add(iNO, bmp)
                            iNO += 1

                        End Using
                    End If
                End Using
            End Using
    End Sub


strangely, with this method I get sometimes just hals of the picture!
The quality is excellent but sometimes part of the picture is exported in the metafile...

Why ????? I have yet to figure out!

Any one here have any idea why this method does not get all the image ???

thanks for any hints



very weird!,,,
the document  is landscape  legal and some of the biases are cut while others are perfect!

still working  on  figuring  out  what  is going  on  with  this Metafile  extraction... any help welcomed....
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)


now I got it to work!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions