Code samples

Code samples for VintaSoft Imaging .NET SDK. Here you can request a code sample.

Board index < VintaSoft Imaging < VintaSoft Imaging .NET SDK and Plug-ins Discussions < Code samples

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

JavaScript: Copy text, which is selected in web viewer, to the clipboard.



JavaScript: Copy text, which is selected in web viewer, to the clipboard.

Post by Alex »

Web image viewer allows to open document (PDF, DOCX, XLSX) and select text in viewer using mouse. By default the viewer does not handle pressing of Ctrl+C key and selected text cannot be copied to the clipboard by pressing Ctrl+C key. If selected text must be copied to the clipboard by pressing Ctrl+C key, this can be done with custom code.

Here is JavaScript code snippet that allows to copy text, which is selected in web viewer, to the clipboard by pressing Ctrl+C key:
// 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.");
    }
}


Page 1 from 1: 1