javascriptjquerycsspdf.jspdfobject

Hide print button when using PDFObject with PDF.js


I'm trying the print button and others when rendering a file using pdf.js. I tried using CSS and it works for Chrome but not Internet Explorer. For Internet Explorer I used javascript. JS works when I load one file but subsequent files are still showing the buttons.

viewer.html

<script type="text/javascript">
    $(function () {

        $('#print').hide();
        $('#viewBookmark').hide();
        $('#openFile').hide();
    });
</script>

viewer.css

button#openFile, button#print, a#viewBookmark {
        display: none;
    }

default.cshtml

$('.file').on('click touchend', function (e) {
        e.preventDefault();
        if ($(this).hasClass('disabled'))
            return;
        var path = $(this).data('path').replace("\\\\", "http://").replace("@pdfFolder", "Uploads");
        var name = $(this).data('name');
        var lastname = $(this).data('lastname');
        name = name.length > 8 ?
            name.substring(0, 5) + '...' :
            name.substring(0, 8);
        lastname = lastname.length > 8 ?
            lastname.substring(0, 5) + '...' :
            lastname.substring(0, 8);
        var tabCount = $('#tabs li').size();
        var uuid = guid();
        $(this).attr('data-position', uuid);
        $('#content').css('display', 'block');
        if (tabCount === 5) {
            $('#maximumTabsModal').modal('show');
        } else {
            $(this).addClass('disabled')
            $('<li role="presentation" data-position="' + uuid + '"><a href="#panel' + uuid + '" aria-controls="panel"' + uuid + ' role="tab" data-toggle="tab">' + name + '<span class="close"></span><br/>' + lastname + '</a></li>').appendTo('#tabs');
            $('<div class="tab-pane" id="panel' + uuid + '"><div id="pdf' + uuid + '" class="pdf"></div></div>').appendTo('.tab-content');
            $('#tabs a:last').tab('show');
            var options = {
                //pdfOpenParams: {
                //    view: "FitV"
                //},
                forcePDFJS: true,
                PDFJS_URL: "pdfjs/web/viewer.html"
            };
            var pdf = PDFObject.embed(path, '#pdf' + uuid, options);
            $('#print').hide();
            $('#viewBookmark').hide();
            $('#openFile').hide();
            $('#exd-logo').hide();
        }
    });

Solution

  • I was able to get the buttons to hide by handling the pagerendered event that PDF.js provides.

    viewer.html

    <script type="text/javascript">
        $(function () {
            document.addEventListener("pagerendered", function (e) {
                $('#print').hide();
                $('#viewBookmark').hide();
                $('#openFile').hide();
            });
        });
    </script>