Skip to main content Skip to footer

How to Hide the DsPDF Viewer Context Menu

There are a couple of methods you can use to hide the Viewer’s built-in context menu. The first method is by removing all items from the context menu. This is possible with the onBeforeOpenContextMenu option, which allows the Viewer context menu to be customized. Then, we can splice the items in the list, similar to the following example: 

const options = { 
		workerSrc: "/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/dspdfviewer.worker.js",		
		onBeforeOpenContextMenu: function (items, mousePosition, viewer) {
            items.splice(0, items.length);
            return true;
		},
		restoreViewStateOnLoad: false
	};

You can test this with the Custom Context Menu demo to quickly see the functionality. Another option is to instead use the system context menu, which can be applied by setting the useNativeContextMenu option to true: 

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

Tye Glenz