Here is JavaScript code snippet that allows to copy text, which is selected in web viewer, to the clipboard by pressing Ctrl+C key:
Code: Select all
// subscribe to the keyup event of document
document.onkeyup = function (event) {
// if Ctrl+C key is pressed
if (event.ctrlKey && event.key === "c") {
// get the text selection tool, which is used by web document viewer
var textSelectionTool = _docViewer.getVisualToolById("TextSelectionTool");
// get selected text
var selectedText = textSelectionTool.get_SelectedText();
// copy text to the clipboard
navigator.clipboard.writeText(selectedText);
// show alert
alert("Text is copied to the clipboard.");
}
}