Responding Armagan - Display Thumbnails For Every Page Of A Document

Here is one of the question from one of you regarding the contents on Display Thumbnails For Every Page Of A Document .

===

Hi. I'd like to thank about your EnhMetaFileBits code, it helped me alot. If you don't mind I'd like to ask you something about that. Can you please give me any hints about how to apply it for every page in a Word document? I'd appreciate any info.

===

Hey man! you are a decent guy - If I were you, I'd shout and say - "THE POST IS INCORRECT! IT DOES NOT EXPLAIN HOW DO I DO IT FOR EVERY PAGE" :)

Thanks for being nicer then me ...

 

Here is the code that "Actually" gets the thumbnails for every page :

 Imports Word = Microsoft.Office.Interop.Word
Imports System.IO

Public Class Form1
    Dim wdApp As Word.Application
    Dim wdDoc As Word.Document
    Dim wdSelect As Word.Range

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        wdApp = New Word.Application
        wdApp.Documents.Open("<DOCNAME>")
        wdApp.Visible = True

        Dim emfData As Byte()
        Dim ms As MemoryStream
        Dim mf As Imaging.Metafile
        Dim pn As Long


        pn = wdApp.ActiveDocument.ActiveWindow.Panes(1).Pages.Count() 'Get the page count

        For i As Long = 1 To pn
            wdApp.Selection.GoTo(Word.WdGoToItem.wdGoToPage, Word.WdGoToDirection.wdGoToAbsolute, i) ' Go to the next page
            wdApp.ActiveDocument.Bookmarks("\Page").Range.Select() 'Select using the magic bookmark "\page"
            Debug.Print("Selected " & i & " page")

            emfData = wdApp.Selection.EnhMetaFileBits 'Get the metafile bits
            ms = New MemoryStream(emfData)
            mf = New Imaging.Metafile(ms)

            mf.Save("c:\upload\page" & i & ".emf") ' Save
            Debug.Print("Saved " & i & " page")

        Next i

        Debug.Print("Done!")
    End Sub
End Class

 

 

del.icio.us tags: Pranav+Wagh, Microsoft+Blogger, Code+Snippet, Developer+Support, Word

Technorati tags: Pranav+Wagh, Microsoft+Blogger, Code+Snippet, Developer+Support, Word