none
Word document to .png

    Question

  • Hi. Is it possible to convert a Word document to .png using VB 2013 Express?

    I basically need the code to check inside a folder for any word documents that has not been converted to .png and convert them to .png, using the same name as the original word doc. The original word docs must remaine. Hope some one can help with some code.  

    Friday, April 28, 2017 3:00 PM

Answers

All replies

  • Primarily, you would either require a third-party library or some other tool that you would use to convert the Word documents to PNG format. However, there is a simple method as well, you can read the file using any interop code in .NET framework, and then read the graphics using the services provided under System.Drawing namespace, that would help you capture the graphics from the screen and then save them as an image (PNG, JPEG, etc.)

    Otherwise, you would have to look for custom third-party solutions and they will definitely not be free. 

    Also, there are a few open source, and free libraries and solutions available as well but they might not be a complete solution and you would have to add pegs to their right places in many occasions; 

    NetOffice on CodePlex. This can help you in reading the Word document, then you can capture the graphics and store then (.Save() function) it, where you need. 


    The sh*t I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem

    Friday, April 28, 2017 3:15 PM
  • The simple method sounds like it will work. I have no idea how.
    Friday, April 28, 2017 3:33 PM
  • Hello,

    Please Add the two dlls (RasterEdge.Imaging.Basic.dll and RasterEdge.Imaging.MSWordDocx.dll) from the trial version of this SDK to your VB.NET project references, you can get these dlls from here:

    https://github.com/prasanjeetd/PdfToWord/find/master

    and then please refer to the code below.

    Private Sub loaddate()
            Dim filename As String = "D:/Demo.docx"
            Dim doc As REDocument = REFile.OpenDocumentFile(filename, New
         DOCXDecoder())
         'use DOCXDecoder open a word file
         Dim pageCount As Integer = doc.GetPageCount()
            'get word's page count 
            For pgIdx As Integer = 0 To pageCount - 1
                Dim aPage As BasePage = doc.GetPage(pgIdx)
                'get page from REDocument
                Try
                    Dim img As REImage = DirectCast(aPage.ToImage(), REImage)
                    'translate page to image
                    'save image
                    REFile.SaveImageFile(img, FolderName & "output" & pgIdx & ".png")
                Catch generatedExceptionName As Exception
                    Debug.WriteLine("Fail to display page " & pgIdx)
                End Try
            Next
        End Sub
    More detailed info, please refer to word to PNG.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 2, 2017 5:45 AM
    Moderator
  • I can not find (RasterEdge.Imaging.MSWordDocx.dll)
    Sunday, May 7, 2017 10:42 AM
  • Hi VB Novice,

    You can get these dlls from this link.

    https://github.com/prasanjeetd/PdfToWord/find/master

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 8, 2017 2:15 AM
    Moderator
  • Ok. This seems to complicated for a novice like me. What about doing the same thing, but instead of Word.docx we use .xps and convert that to .png  The .xps does not have to be visible on screen, once converted the .png must be shown in a panel or picture box.  

    Wednesday, May 10, 2017 8:42 AM
  • Hendri,

    You want something to do what is impossible.

    I take a analog sample. "How would you convert petrol to a car." 

    Crazy is it not. 

    A Word document is a long string of characters which is made to a presentation of screen. 

    However, how it looks is depending from the used screen and the way the user has set its screen options. It looks to you maybe if that is not the case with pdf or xps but still it does.

    However, if it is as a kind of short image then there is maybe a solution. You can first show the document using word interop on screen and get it then with Image.copyfromscreen.

    That is not difficult to use.

    Look here from a sample on our website.

    http://www.vb-tips.com/CreateImageAndCopyFromScreen.ASPX

    In this case there is no need to present it then on screen of course 

    Nevertheless, it is then a clumsy novice way.


    Success
    Cor

    Wednesday, May 10, 2017 8:56 AM