|
-
Apr 3rd, 2009, 08:59 AM
#1
Thread Starter
Addicted Member
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.
-
Apr 3rd, 2009, 12:00 PM
#2
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 -
-
Apr 3rd, 2009, 01:40 PM
#3
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
-
Apr 3rd, 2009, 03:24 PM
#4
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.
-
Apr 3rd, 2009, 04:26 PM
#5
Addicted Member
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. 
-
Apr 6th, 2009, 09:18 AM
#6
Thread Starter
Addicted Member
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?
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
|