Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Converting a Word Document to an Image (VB)

    Does anyone know how to use Visual Basic (6, .NET, or VB for Applications) to convert an entire Word Document to an image (jpeg preferably)? I've attempted to do this by copying the entire contents of a Word document to the clipboard, then programmatically turning the clipboard contents into a bitmap. This will work, but the resulting image quality is very poor. If anyone knows of a more direct way to accomplish this, please let me know.

    Thanks!!!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Converting a Word Document to an Image (VB)

    Welcome to Woody's Lounge!

    For a multi-page document this will be problematic anyway - an image containing a (say) 14 page Word document will be HUGE, and difficult to handle.

    Perhaps you could tell us what you want to accomplish. There may be other ways of doing it.

  3. #3
    New Lounger
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Converting a Word Document to an Image (VB)

    The documents will actually be very small... the size of a classified ad, and they won't contain any embedded objects. The documents will have formatted text, but nothing more complicated than that. I have thought of trying to do a screen capture, but I wouldn't know where to begin cropping the screenshot.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Converting a Word Document to an Image (VB)

    If you have fax software (WinFax for example), you can "print" the Word document to a TIFF file. However, this will be a whole page again...

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Converting a Word Document to an Image (VB)

    If you can accept 1 page = 1 image, you can send each page to Powerpoint and create an image for each page.

  6. #6
    New Lounger
    Join Date
    Aug 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Converting a Word Document to an Image (VB)

    Unfortunately, most users of the utility I am trying to create won't have PowerPoint. In a bit more detail, here is what I would like to accomplish:

    If a user was to copy a Word document to the clipboard manually (simply by selecting the entire document, then selecting Edit --> Copy), the user could then open a paint program (the generic Windows Paint program, Paint Shop Pro, PhotoShop, etc.) and select Edit --> Paste, and an image of the document would be displayed (I am guessing the Word document is converted to a metafile before being pasted). Since this is possible, there must be some way to convert the Word document to a valid image type and paste that resulting image into a picturebox.

    I have actually managed to do this in VB6. According to some VB6 code I've written, the clipboard contents of a Word document are stored as a metafile, which I can load into a VB6 picturebox. Then I am able to save the image as a bitmap (which is of significantly lower quality than I need) using the VB6 SavePicture function. I really need the image to be a high-quality jpeg, which I cannot seem to accomplish with VB6.

    Since I could not generate a jpeg version of the image in VB6, I decided to try writing the program in VB .NET. In .NET, a function exists within the PictureBox's Image property that allows a programmer to convert and save an image as a variety of image types, including jpeg. Getting clipboard contents in .NET is not quite the same as it is in VB6. Below is a subroutine I am working with in VB .NET with comments as to what is going on and what isn't working:

    Private Sub pasteDocumentFromClipboard()
    'Store the contents of the clipboard in an IDataObject.
    Dim data As IDataObject = Clipboard.GetDataObject()

    'Check for metafile data on the clipboard. This test passes, and the code within the 'if' statement is executed.
    If data.GetDataPresent(DataFormats.MetafilePict) Then
    'Place the contents of the clipboard into a picturebox control.
    picDocument.Image = data.GetData(DataFormats.MetafilePict, True)

    'The above line does not work. In fact, if I test the statement:
    'If data.GetData(DataFormats.MetafilePict) Is Null Then (...do something...),
    'The code within the 'if' block will be executed, meaning the statement has
    'returned a null reference.
    End If
    End Sub

    Basically, this means that I can copy the Word document to the clipboard, have .NET recognize it as a "MetafilePict" (or as any of the following other formats: Embed_Source [whatever that is... the Word default format perhaps?], Unicode Text, Text, HTML, Rich Text, or NoteshNote), but not display the contents of the clipboard in the picturebox. If I could just get the data into the picturebox, I'd be all set, and I'd probably start doing backflips here in the office. ;-)

    Sorry for being so verbose... thanks for the quick replies!

  7. #7
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Converting a Word Document to an Image (VB)

    In Word2003, you could try to "File > Print" to the "Microsoft Office Document Image Writer".
    Print to a file.

    It does a respectable job; and you can save the result as a *.tif bitmap, with options about lossy/lossless compression.

    I don't know if there's an interface to automate the process. But perhaps you can fudge something.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

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