none
how to make the pages in doc to image RRS feed

  • Question

  • hi 

    sorry for my poor english.

    i want to realize a function like Navigation pane in the word2010. now i don't know how to make the pages in doc to image by vsto. 

    Tuesday, May 29, 2012 6:17 AM

Answers

All replies

  • Could you perhaps get the window handle of the Microsoft Word application, and then use some WIN32 calls such as this :-

        public void ScreenshotWindow(IntPtr windowHandle) {
           
    Rect Rect = new Rect();

           
    GetWindowRect(windowHandle, out Rect);
           
    int width = Rect.right - Rect.left;
           
    int height = Rect.bottom - Rect.top;

           
    IntPtr windowDeviceContext = GetWindowDC(windowHandle);
           
    IntPtr destDeviceContext = CreateCompatibleDC(windowDeviceContext);
           
    IntPtr bitmapHandle = CreateCompatibleBitmap(windowDeviceContext, width, height);
           
    IntPtr oldObject = SelectObject(destDeviceContext, bitmapHandle);
           
    BitBlt(destDeviceContext, 0, 0, width, height, windowDeviceContext, 0, 0, CAPTUREBLT | SRCCOPY);
           
    SelectObject(destDeviceContext, oldObject);
           
    DeleteDC(destDeviceContext);
           
    ReleaseDC(windowHandle, destDeviceContext);

           
    Image screenshot = Image.FromHbitmap(bitmapHandle);
           
    DeleteObject(bitmapHandle);

            screenshot
    .Save("C:\\Screenshots\\" + windowHandle.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
       
    }

    Tuesday, May 29, 2012 7:47 AM
  • window can display more then one page, or even be in middle between pages, so this is not a solution. I think you could use Range.CopyAsPicture and select single page into the range. How to do this properly and handle all corner cases - i do not know, you should ask on forum for word developers.

    http://msdn.microsoft.com/en-us/library/ff836633
    Tuesday, May 29, 2012 8:39 AM
  • Thank you for your reply. What i want to achieve is each page has a thumbnail. And they should be shown in my listview control. now i really don't know how to get the thumbnail, do you have any ideas?
    Tuesday, May 29, 2012 8:41 AM
  • i assume that getting image problem is solved or will be solved. Now you can use standard .net classes like http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx . As far as i remember also paid components have such functionality, for example Aspose.

    Tuesday, May 29, 2012 9:00 AM
  • Thank you very much.  I'll try what you said and  thanks again!
    Tuesday, May 29, 2012 9:22 AM