In This Topic
Reference Guides / JavaScript API / Actions / Interface / AddSelectedTextContextMenuItem

AddSelectedTextContextMenuItem

In This Topic
 AddSelectedTextContextMenuItem

This function allows you to add a custom item to the selected text contextual menu.

AddSelectedTextContextMenuItem: function (docuViewareID, caption, callback, icon)

Parameters

docuViewareID
The identifier for the DocuVieware™ instance you want to add the contextual menu item to.
caption
A string that represents the text that will be displayed as the menu option.
callback
A function that will be executed when the user clicks on the menu item.
It provides an array of objects containing all the selected text areas with the following prototype: { pageNo, coordinates: { top, left, height, width } }.
The measurement unit for the coordinates is inches relative to the document page.
icon
Av HTML element that represents the button icon.

Return Value

1 if error, 0 if success.

Example of usage

This code adds two context menu items, one will display the coordinates of the selected text sections in the console and the other will highlight the selected text in green.

var icon = '<svg viewBox="0 0 512 512" width="100%" height="100%"><path d="m 219.2115,319.40794 c -6.81606,0 -13.63211,-2.58799 -18.84246,-7.79672 -48.69546,-48.68036 -48.69546,-127.92516 0,-176.63827 l 98.30847,-98.277972 c 23.59403,-23.586713 54.9872,-36.59216444 88.34654,-36.59216444 33.35934,0 64.75251,13.00545144 88.34654,36.59216444 48.69546,48.713114 48.69546,127.925162 0,176.638272 l -44.92697,44.91303 c -10.38793,10.38471 -27.26421,10.38471 -37.65214,0 -10.38793,-10.3847 -10.38793,-27.25576 0,-37.64046 l 44.92697,-44.91303 c 27.95237,-27.94371 27.95237,-73.41365 0,-101.35735 -13.5338,-13.5296 -31.55702,-20.998726 -50.6944,-20.998726 -19.13738,0 -37.1606,7.469126 -50.6944,20.998726 l -98.30847,98.27797 c -27.95237,27.9437 -27.95237,73.41364 0,101.35735 10.38793,10.3847 10.38793,27.25575 0,37.64046 -5.21035,5.20873 -12.0264,7.79672 -18.84245,7.79672 z"></path><path d="m 124.86814,512 c -33.359342,0 -64.752513,-13.00545 -88.346545,-36.59216 -48.69546,-48.68036 -48.69546,-127.92516 0,-176.63828 l 44.92697,-44.91303 c 10.387928,-10.3847 27.264215,-10.3847 37.652145,0 10.38793,10.38471 10.38793,27.25576 0,37.64046 l -44.926972,44.91304 c -27.952374,27.9437 -27.952374,73.41364 0,101.35734 13.533799,13.5296 31.524252,20.99873 50.694402,20.99873 19.17015,0 37.1606,-7.46913 50.6944,-20.99873 L 273.871,339.4894 c 27.95238,-27.9437 27.95238,-73.41364 0,-101.35734 -10.38792,-10.38471 -10.38792,-27.25576 0,-37.64047 10.38793,-10.3847 27.26422,-10.3847 37.65215,0 48.69546,48.68036 48.69546,127.92516 0,176.63828 l -98.30847,98.27797 C 189.62065,498.99455 158.22748,512 124.86814,512 Z"></path></svg>';

DocuViewareAPI.AddSelectedTextContextMenuItem("DocuVieware1", "Coordinates", function (areas) { console.log(areas); }, icon );
DocuViewareAPI.AddSelectedTextContextMenuItem("DocuVieware1", "Green", function () { DocuViewareAPI.HighlightSelectedText("DocuVieware1", "#00FF00"); }, icon );