Documents for PDF .NET Edition
GrapeCity Documents PDF Viewer / GcDocs PDF Viewer Features / Custom Context Menu
In This Topic
    Custom Context Menu
    In This Topic

    GcDocs PDF Viewer 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 GcDocs PDF Viewer:

    Index.cshtml
    Copy Code
    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 GcDocs PDF Viewer's context menu to use browser's context menu by using below code:

    Index.cshtml
    Copy Code
    var viewer = new GcPdfViewer("#root", { useNativeContextMenu: true });
    

    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).