-
Oct 24th, 2011, 12:31 PM
#1
Thread Starter
Member
Extracting Images from a Word DOC
Hello,
I have been trying to find code that would allow me to access the inline shapes of a Word Document and copy them into my .NET application as bitmaps. Using various websites I've cobbled together the following code:
Code:
Dim app As New Word.Application
Dim doc As Word.Document = app.Documents.Open(e.Argument.ToString, False, True, False)
For Each ishp As Word.InlineShape In doc.InlineShapes
ishp.Select()
app.Selection.CopyAsPicture()
If Clipboard.ContainsImage Then
Dim bmp As Bitmap = Clipboard.GetImage
' work with bmp
bmp.Dispose()
End If
Next
doc.Close()
app.Quit()
Unfortunately, the code that declares and sets the bitmap never gets executed, because the clipboard doesn't contain an image. However, if I set a break point directly after I call CopyAsPicture(), I am able to open Paint and paste a picture, i.e., what was copied.
I read somewhere that Word doesn't use the standard Clipboard that is available to .NET. First, I find this a little strange, but I know Microsoft has done strange things in the past. More importantly, irregardless of any strange practices, how do I get the image off of the clipboard?
Wherever Word copies the inline shape, Paint can retrieve it, so how do I?
EDIT
Okay, I just tried a completely basic example and the above code worked. The difference between this basic version and the original version is the original uses a BackgroundWorker to open Word and extract the images.
I don't know very much about threading, but I'm guessing that the thread that the background worker is on does not "see" the same Clipboard as the thread that Word copies to. Perhaps someone will know more about this.
Last edited by arcanine; Oct 24th, 2011 at 01:52 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|