none
How to insert GDI+ Object into Word Document Using C# .NET RRS feed

  • Question

  • I'm newbie developer in C# .net. I'm try using Interop.Word to generate word document for database design documentation. I've problem to draw my GDI+ object in UserControl my WindowsFormApplication to Word 2007 document. I need help for this problem because this is the basic my application concept to generate the database design documentation. Thanks.
    Wednesday, April 6, 2011 1:05 PM

Answers

  • Hi Lutfi

    Since you're not using the VSTO technology, I'm going to move your question to the Word Developer forum, where it will be more on-target.

    But FWIW there is no way for you to directly draw GDI objects on an Office document surface. You need to either copy them to the clipboard, then use the Range or Selection PASTE method of the Word object model. Or you need to save the GDI object to disk, as a standard graphics file, then use the ADDPICTURE method of either the Shapes or InlineShapes object to bring it into the document.


    Cindy Meister, VSTO/Word MVP
    Wednesday, April 6, 2011 2:01 PM
    Moderator

All replies

  • Hi Lutfi

    Since you're not using the VSTO technology, I'm going to move your question to the Word Developer forum, where it will be more on-target.

    But FWIW there is no way for you to directly draw GDI objects on an Office document surface. You need to either copy them to the clipboard, then use the Range or Selection PASTE method of the Word object model. Or you need to save the GDI object to disk, as a standard graphics file, then use the ADDPICTURE method of either the Shapes or InlineShapes object to bring it into the document.


    Cindy Meister, VSTO/Word MVP
    Wednesday, April 6, 2011 2:01 PM
    Moderator
  • Ok. I'll try your suggestion. Thanks for your help.
    Thursday, April 7, 2011 1:51 AM
  • Hi Lufti

    Ah, I forgot one other approach available to you if you're working with Word (this doesn't work in other Office apps):

    IF GDI+ allows this (I don't know), you can "stream" the GDI information to a graphics file format (jpg, for example). It can then be inserted into Word using the Range.InsertXML method. The XML inserted needs to be in valid Office Open XML (flat package format). You can find more information at OpenXMLDeveloper.org and in the Open XML SDK forum.


    Cindy Meister, VSTO/Word MVP
    Thursday, April 7, 2011 7:19 AM
    Moderator
  • Thanks again, Cindy. Although I didn't  familliar yet with those XML "stream" method, I'll try it as alternative method to put GDI in Word Document. Are there any more simple method to insert GDI object into Word Document (like your first answer) ? Thanks a lot.
    Thursday, April 7, 2011 7:35 AM