Q:
Hi I am testing the WebViewer 1.5.0 (HTML5 version, no silverlight, no flash) client inside a website to display pdf files (after they have been converted to .xod format). Everything works fine. I would just like to ask if it is possible, from javascript, to get the text that the user selects inside the viewed pdf. I already have successfully made tests about getting via javascript the text selection of a normal text inside a web page, but since the contents of the pdf are displayed within a <canvas> element I would like to know if and how that is also possible with javascript.
----
A: It is possible to get the selected text from JavaScript. Assuming that you have a reference to a WebViewer object you could use code something like: myWebViewer.getInstance().docViewer.GetSelectedText()
If you're interested in learning about other capabilities of the HTML5 viewer you can browse through the API documentation at http://www.pdftron.com/webviewer/demo/html5/doc/
readerControl.docViewer.on('textSelected', $.debounce(500, async (e, quads, text, pageIndex) => {
await extractor.begin(page, new PDFNet.Rect(topLeft.x, topLeft.y - 3, bottomRight.x, bottomRight.y), PDFNet.TextExtractor.ProcessingFlags.e_remove_hidden_text);
const word = await line.getWord(i);const style = await word.getStyle();const font = await style.getFontName();