[]
        
(Showing Draft Content)

Custom Context Menu

DsPdfViewer provides 'Copy' and 'Print' options in its context menu, by default. However, the context menu options can be customized for other operations, like searching selected text by using different Web Search Engines.

The below image displays custom context menu when selected text is right clicked.

PDF Viewer displaying custom context menu to search selected text using various Web Search engines.

To configure custom context menu in DsPdfViewer:

viewer.options.onBeforeOpenContextMenu = function (items, mousePosition, viewer) {
    var selectedText = viewer.getSelectedText();

    if (selectedText) {
        // Remove existent items:
        items.splice(0, items.length);
        // Add own menu items:
        items.push({
            type: 'button',
            text: 'Search using Google',
            onClick: function () {
                window.open('http://www.google.com/search?q=' + encodeURI(selectedText), '_blank');
            }
        });

        items.push({
            type: 'button',
            text: 'Search using Bing',
            onClick: function () {
                window.open('https://www.bing.com/search?q=' + encodeURI(selectedText), '_blank');
            }
        });
    }
    return true;
};

You can also disable the DsPdfViewer's context menu to use browser's context menu by using below code:

var viewer = new DsPdfViewer("#root", { useNativeContextMenu: true });

!type=note

Note: The default value of useNativeContextMenu is false**.** When it is set to true, some context menu functions become unavailable (for example, actions of Editor and Reply tool).