Convert "Selection.CopyAsPicture()" to Image File?


  • Hello,

    I failed to find a solution for my problem.

    I want to save the Word Selection as an Image file.

    It successfully copies the data from word file, but i cannot get an image from clipboard using c#. However, when i close the app and normally paste it in doc file .... it works fine!

    I am using the following CODE!!




     Microsoft.Office.Interop.Word.Application app;
       Microsoft.Office.Interop.Word.Document oDoc;
       app = new Microsoft.Office.Interop.Word.Application();
       oDoc = app.Documents.Open("C:\\test\\test.docx");
       //Set the range for First Page
        oDoc.Bookmarks["\\Page"].Range.End - 1);
       if (Clipboard.GetDataObject() != null) 
        IDataObject data = Clipboard.GetDataObject();
        if (data.GetDataPresent(DataFormats.Bitmap, true)) // Return False
         Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true);
         image.Save( "C:\\image.jpg");
        else if (data.GetDataPresent(DataFormats.MetafilePict)) // Return TRUE but failed to convert as image
         Stream myStream = (Stream)data.GetData(DataFormats.MetafilePict);
         Image m = Metafile.FromStream(myStream);


    I am using Studio 2010 and Office 2007.


    Could you please help me out!!



    • 이동됨 Paul Zhou 2011년 3월 3일 목요일 오전 2:33 not supported (From:.NET Base Class Library)
    2011년 2월 28일 월요일 오후 5:28

모든 응답