Results 1 to 6 of 6

Thread: Display first page of .doc in PictureBox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Display first page of .doc in PictureBox

    Hello all,
    A few years ago, I remember seeing an MS Access application where the programmer displayed the first page of a Word document as a thumbnail on a form. I'm guessing that its highly possible that this is well within the limits of .NET - could anybody point me in the right direction to read-up on how I might do this?
    Thanks.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Display first page of .doc in PictureBox

    You can try using office interop to open the .doc file and print it. Choose Microsoft Office Document Image Writer as the printer and it'll save the document to tif file. I beleive you can also specify which pages to print (to image), so if you print only 1st page then you have a tif image of 1st page. Once you have the image, you can display it in your picturebox control.
    Not that I've done it programmatically, but I convert office documents to images all the time using Microsoft Office Document Image Writer, so I would guess it's very feasible to do it programatically.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Display first page of .doc in PictureBox

    Going off stanav's idea because I thought it was kinda interesting this is what I came up with:

    Code:
    Imports Microsoft.Office.Interop 
    Public Class Form1 
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
            Dim wordapp As New Word.Application 'new word app 
            wordapp.Visible = False 'hide word app 
            wordapp.Documents.Open("path To DocumentToPrint", , True) 'open document as readonly 
            wordapp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone 'stop alerts 
            wordapp.ActivePrinter = "Microsoft Office Document Image Writer" 'Set the printer 
            wordapp.Documents(1).PrintOut(True, , Word.WdPrintOutRange.wdPrintAllDocument, "c:\PathToOutputFolder\filename.tif", _ 
                                          , , Word.WdPrintOutItem.wdPrintDocumentContent, 1, "", Word.WdPrintOutPages.wdPrintAllPages, _ 
                                          False, True, , False, 0, 0, 0, 0) 'Print parameters 
        End Sub 
    End Class
    Edit the printing parameters as you see fit.

    Be sure to add the Imports line and a reference to Microsoft Word 11.0 Object Library

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Display first page of .doc in PictureBox

    If you are using Word 2007 (docx) documents and they are being saved with the thumbnail, you can extract that thumbnail without using word. Basically you just have to programatically unzip the file and extract the docProps/thumbnail.wmf file.

  5. #5
    Addicted Member
    Join Date
    Nov 2006
    Location
    Minnesota
    Posts
    235

    Re: Display first page of .doc in PictureBox

    You could try this:


    Code:
       Dim pbPicture As New PictureBox
    
    
                Dim imgImage As Drawing.Image = Drawing.Image.FromFile("Somefilepath")
                Dim imgThumb As Drawing.Image = imgImage.GetThumbnailImage(64, 64, Nothing, IntPtr.Zero)
                pbPicture.Image = imgThumb
    It's fairly straight forward -- works for obvious imagefiles (jpeg,jpg,bmp, png,) , pdf can't remember what it does to word docs though.
    If someone has helped you, please make sure to rate them.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: Display first page of .doc in PictureBox

    Thanks everybody. Though its not as quick as I'd hoped, this gives me enough to work with. I'll probably display the "Word" icon or something until the tiff file has been created.
    Any ideas how I suppress the "Windows Picture and Fax Viewer" after the tiff file is written?
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width