none
C# Getting Ink Objects from Word Document RRS feed

  • Question

  • I have a C# application which integrates with office and has a "word" control in order to load the document.  This document will have ink markup.  I want to be able to take the markup from the word document and convert the "shape" (Word.Shape) objects into Ink (Microsoft.Ink) objects so I can convert the markup into text.

    The following code, I loop through each of the shape objects in the word document and convert the pen markings into an Ink object.  The explicit conversion to an Ink object obviously doesn't work. 

    int num_shapes = objWinWordControl.document.Shapes.Count;
    for (int i = 1; i <= num_shapes; i++)
    {
        object item_num = i;
        Ink myinkobj = new Ink();

        myinkobj = (Ink) objWinWordControl.document.Shapes.Item(ref item_num);
    }

    Is there a nice way to get access to the ink markup to the word document in my C# application? 

    In word there is a right menu item "copy ink as text".  Perhaps I could somehow select each shape object individually and then call this command.  Could someone give me some direction as to how I should solve this?
    Monday, June 25, 2007 8:47 PM

Answers

  • I found a way to get at the ink data!  It's actually quite simple. One simply has to select each Word.Shape, use Word to copy the shape, and then paste the "Ink Serialized Format" from the clipboard into an ink object.  I'm not exactly sure why I overlooked this.  I guess I assumed a generic "copy" would not store ink data in the clipboard.

    Code Snippet
    int size = objWinWordControl.document.Shapes.Count;

                foreach (Word.Shape obj in objWinWordControl.document.Shapes)

                {

                   

                    Object asdf = new Object();

     

                    //if object is an ink object

                    if (obj.Type.ToString() == "23") // 23 is identifier of ink object in Word (I'm pretty sure)

                    {

                        //By selecting document, unselects the previous shape

                        objWinWordControl.document.Select();

     

                        //select current object

                        obj.Select(ref asdf);

     

                        //Copy the selection to the clipboard

                        objWinWordControl.document.ActiveWindow.Selection.Copy();

                      

                        Ink inkObj = new Ink();

                        inkObj.ClipboardPaste(); //puts the copied ink from clipboard into ink object (SWEET!)

                       

     

      //and so on

                    }

    }

                   


    Monday, July 23, 2007 2:44 PM

All replies

  • Hi Jesse.

     

    Unfortunately, Microsoft Office Word does not expose the ink data in its object model. As you are aware, the Word.Shape members are specific to objects in the drawing layer rather than to ink. Having said that, we are looking into another way to get the ink data. We'll get back to you soon and let you know if we do find a successful workaround.

     

    I just didn't want to leave you thinking we were ignoring your post.

     

    Best of luck.

     

    Eliot - MSFT

    Wednesday, July 4, 2007 5:27 PM
  • I found a way to get at the ink data!  It's actually quite simple. One simply has to select each Word.Shape, use Word to copy the shape, and then paste the "Ink Serialized Format" from the clipboard into an ink object.  I'm not exactly sure why I overlooked this.  I guess I assumed a generic "copy" would not store ink data in the clipboard.

    Code Snippet
    int size = objWinWordControl.document.Shapes.Count;

                foreach (Word.Shape obj in objWinWordControl.document.Shapes)

                {

                   

                    Object asdf = new Object();

     

                    //if object is an ink object

                    if (obj.Type.ToString() == "23") // 23 is identifier of ink object in Word (I'm pretty sure)

                    {

                        //By selecting document, unselects the previous shape

                        objWinWordControl.document.Select();

     

                        //select current object

                        obj.Select(ref asdf);

     

                        //Copy the selection to the clipboard

                        objWinWordControl.document.ActiveWindow.Selection.Copy();

                      

                        Ink inkObj = new Ink();

                        inkObj.ClipboardPaste(); //puts the copied ink from clipboard into ink object (SWEET!)

                       

     

      //and so on

                    }

    }

                   


    Monday, July 23, 2007 2:44 PM