10 Replies Latest reply on Nov 4, 2009 6:50 AM by Patrick Leckey

    Highlighting text in C#

    bp54321

      I started the JSObjectControl.cs example thats downloaded with the SDK 9 as a base.  I've modified it to add a watermark to each page. (That works).  I am able to search thru the words on each page and find a match on a string. (That also works).  What I want to do is Highlight those matches and then save the document.  (I can successfully do the save).  What I haven't figured out is how to highlight.  I've searched the forums and web and while I can find many examples in VB, nothing using the InvokeMethod used in the C# example.  I've tried all kinds of parms passed into "addAnnot" method but all that is ever returned from the call is a null object, and of course no highlighting on the page.  Below is the code up to the point where I found a match and want to highlight the word.  The getPagenthwordquads returns a quad of valid numbers so all looks good until then.  Can anyone help me with the required code to finish this off.

        for (int i = 0; i < nPages; i++)

                      {

                          // check each word in a page

                          object[] getPageNumWordsParam = { i };

                          double nWords = (double)T.InvokeMember(

                              "getPageNumWords",

                              BindingFlags.InvokeMethod |

                              BindingFlags.Public |

                              BindingFlags.Instance,

                              null, jsObj, getPageNumWordsParam);

       

                          for (int j = 0; j < nWords; j++)

                          {

                              //get a word

                              object[] getPageNthWordParam = { i, j };

                              String word = (String)T.InvokeMember(

                                  "getPageNthWord",

                                  BindingFlags.InvokeMethod |

                                  BindingFlags.Public |

                                  BindingFlags.Instance,

                                  null, jsObj, getPageNthWordParam);

       

                              // compare the word with what the user wants

                              int result = String.Compare(word, "Word to match");

       

                              // if same

                              if (result == 0)

                              {

                                  //nCount = nCount + 1;

                                  object[] quads = (object[])T.InvokeMember(

                                      "getPageNthWordQuads",

                                      BindingFlags.InvokeMethod |

                                      BindingFlags.Public |

                                      BindingFlags.Instance,

                                      null, jsObj, getPageNthWordParam);

       

      ********************** Help needed here to Highlight the found word. *************************************************

       

      Thanks