locked
Creating a thumbnail from a word document RRS feed

  • Question

  • Hi all,

    Im trying to create a thumnail of the firstpage of an Word document.
    I googled a lot for this, but didn't find any solutions. Hopefully you can help me.

     Doc.Select(); 
     Doc.Application.Selection.CopyAsPicture(); 
      
     // I tried to work with the two following methods 
     Clipboard.GetData(DataFormats.EnhancedMetafile); // no return, application is cancelled 
     Clipboard.GetData(DataFormats.MetafilePict); // return a memorystream with 16 byte 

    thanks in advance,

    Omid

    CODEholism.com
    Thursday, October 16, 2008 10:45 AM

Answers

  • Hi,

    What is the thumbnail? If it is a image,I think you can use the following code to get it on the clipboard and save it .
                    InlineShapes shapes = Doc.InlineShapes;  
                    int i = 0;  
                    foreach (InlineShape shape in shapes)  
                    {  
                         if (shape.Type == WdInlineShapeType.wdInlineShapePicture)  
                        {  
                            shape.Select();  
                            shape.Application.Selection.CopyAsPicture();  
     
                            IDataObject data = Clipboard.GetDataObject();  
     
                            if (data.GetDataPresent(DataFormats.Bitmap))  
                            {  
                                Image image = (Image)data.GetData(DataFormats.Bitmap, true);  
                                image.Save("c:\\111.bmp"), System.Drawing.Imaging.ImageFormat.Bmp);  
                            }  
                        }  
                    }
     

    Best regards,
    Harry
    • Proposed as answer by Harry Zhu Tuesday, October 21, 2008 8:11 AM
    • Edited by Harry Zhu Tuesday, October 21, 2008 8:44 AM spelling
    • Marked as answer by Harry Zhu Tuesday, October 21, 2008 8:44 AM
    Monday, October 20, 2008 9:00 AM

All replies

  • Hi,

    What is the thumbnail? If it is a image,I think you can use the following code to get it on the clipboard and save it .
                    InlineShapes shapes = Doc.InlineShapes;  
                    int i = 0;  
                    foreach (InlineShape shape in shapes)  
                    {  
                         if (shape.Type == WdInlineShapeType.wdInlineShapePicture)  
                        {  
                            shape.Select();  
                            shape.Application.Selection.CopyAsPicture();  
     
                            IDataObject data = Clipboard.GetDataObject();  
     
                            if (data.GetDataPresent(DataFormats.Bitmap))  
                            {  
                                Image image = (Image)data.GetData(DataFormats.Bitmap, true);  
                                image.Save("c:\\111.bmp"), System.Drawing.Imaging.ImageFormat.Bmp);  
                            }  
                        }  
                    }
     

    Best regards,
    Harry
    • Proposed as answer by Harry Zhu Tuesday, October 21, 2008 8:11 AM
    • Edited by Harry Zhu Tuesday, October 21, 2008 8:44 AM spelling
    • Marked as answer by Harry Zhu Tuesday, October 21, 2008 8:44 AM
    Monday, October 20, 2008 9:00 AM
  • Hi Harry thanks for the reply,

    I would like to create an image of the "hole first page" of an Document.
    Is there a way to do this?

    regards,

    Omid

    CODEholism.com
    Tuesday, October 28, 2008 9:22 AM
  • Hi Omid,

    Have a look at the following document:http://www.vikramlakhotia.com/Capturing_the_image_of_the_screen_using_C.aspx
    The author use CopyFromScreen to print screen .
    Hope it will help.

    And for the office question ,please ask in office development.
     http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.officedev&lang=en&cr=US

    Best regards,
    Harry
    • Edited by Harry Zhu Tuesday, October 28, 2008 9:45 AM edit
    Tuesday, October 28, 2008 9:35 AM