The universal viewer is a higher level wrapper for the individual viewing technologies (HTML5, Silverlight and Flash) and exposes things that are common to all of them. If you want to make more advanced customizations or customizations specifically for the HTML5 viewer then you may have to drop down to the lower level ReaderControl.js and ReaderControl.html files.
For your followup question there are a few things to be clarified and changed. First is that it depends where your button that is triggering this is. If the button will be inside ReaderControl.html then it's simpler as you can add that code to a config file and just change var docViewer = window.WebViewerUniversalInstance.webViewer.getInstance().docViewer; to var docViewer = readerControl.docViewer. This is because the Tools and Annotations namespaces are on the window of the ReaderControl window which is inside an iframe. When you use a config file the code is executed inside this window's context so you can use them just like above.
However from your code it seems like the button is outside the viewer iframe. That code with outerWindow and contentWindow is a bit of a hack that allows the outer window to reference those namespaces on the inner window. Basically we need to get a reference to the window object of the iframe. So from universal.js one way we can get a reference to the iframe's window is like: $("#documentContainer iframe")[0].contentWindow.
So inside your click handler you could have something like: var iframeWindow = $("#documentContainer iframe")[0].contentWindow;
And then later have: new iframeWindow.Annotations.TextHighlightAnnotation() and new iframeWindow.Tools.TextHighlightCreateTool(docViewer)
The next issue with the quads is something we need to improve. The code you took is from the text position sample which uses Document.GetTextPosition() which passes a quads parameter that has x1, y1, etc properties. Internally this exposes these properties and so instead you can use the GetPoints function to do that here. You would change the two lines with quads to the following and they would have the properties you expect:
var firstChar = result.quads[0].GetPoints();
var lastChar = result.quads[result.quads.length - 1].GetPoints();
What should ideally happen is that the text search should return quads with those properties already and there should be better documentation on the quads in general which we'll work on improving.
The last issue has to do with something that is also a bit specific to the GetTextPosition sample. In that sample one quad will be returned for each character specified. In this case the first and last quads aren't going to be the same so when it centers the firstx and finalx variables this is fine since it's just centering over different individual characters. However in your searching case there is one quad being returned for the entire word. This means the first and last quad will be the same and if you center x1 and x2 it will be the same as centering x3 and x4 so the width will be 0!
So in this case you could probably just have something like the following just shifting over the quads by one pixel:
var firstx = firstChar.x1 + 1;
var finalx = lastChar.x3 - 1;
Once I did this I was able to get it to work. If you don't do the shifting then I've found that if your search term is in the middle of a larger word then sometimes the selection will select an extra character.
Let me know if you have any issues with this or if you need some further clarification.
Matt Parizeau
Software Developer
PDFTron Systems Inc.