VintaSoft Imaging .NET SDK 15.2: Documentation for Web developer
In This Topic
Create new menu button for Web Document Viewer UI
In This Topic
Here is JavaScript code that shows how to create UI-button, which allows to show information about opened PDF document, and add new button to the main menu of web document viewer:
/**
 * Main function.
 */
function __main() {
    ...

    // create the default web document viewer settings
    var docViewerSettings = new Vintasoft.Imaging.DocumentViewer.WebDocumentViewerSettingsJS("documentViewerContainer");

    // get items of document viewer
    var items = docViewerSettings.get_Items();

    // get the main menu of document viewer
    var mainMenu = items.getItemByRegisteredId("mainMenu");
    // if main menu is found
    if (mainMenu != null) {
        // get items of main menu
        var mainMenuItems = mainMenu.get_Items();
        // create button
        var showPdfDocumentInfoButton = __createPdfDocumentInfoButton();
        // add the button to the menu panel
        mainMenuItems.addItem(showPdfDocumentInfoButton);
    }

    // create the document viewer
    var docViewer = new Vintasoft.Imaging.DocumentViewer.WebDocumentViewerJS(docViewerSettings);

    ...
}

/**
 Creates UI button that allows to show information about opened PDF document.
*/
function __createPdfDocumentInfoButton() {
    return new Vintasoft.Imaging.DocumentViewer.UIElements.WebUiButtonJS({
        title: "Show information about PDF document",
        onClick: function (event, uiElement) {
            // get the document viewer
            var docViewer = uiElement.get_RootControl();
            // if it exist
            if (docViewer != null) {
                // get image viewer
                var viewer = docViewer.get_ImageViewer();
                // get focused image
                var focusedImage = viewer.get_FocusedImage();
                // get PDF document page associated with focused image
                var pdfPage = Vintasoft.Imaging.Pdf.WebPdfDocumentControllerJS.getPageAssociatedWithImage(focusedImage);
                // message with information about PDF document
                var message = "";
                // if PDF page exists
                if (pdfPage != null) {
                    // get PDF document
                    var doc = pdfPage.get_Document();
                    // if information about PDF document is available
                    if (doc.isDocumentInfoReceived()) {
                        // get information about PDF document
                        var info = doc.getDocumentInfo();
                        // add information about document to the message
                        for (var key in info) {
                            message += key + " : " + info[key] + "\n";
                        }
                    }
                    // else
                    else {
                        // specify that information about PDF document is not available
                        message = "Information about PDF document is not available, call the requestDocumentInfo method."
                    }
                }
                // else
                else {
                    // specify that PDF document, which is associated with focused image, does not exist
                    message = "The focused image is not associated with PDF page.";
                }
                // show message
                alert(message);
            }
        }
    });
}