Hide print button when using PDFObject with PDF.js

Antarr Byrd picture Antarr Byrd · Jun 20, 2016 · Viewed 8.8k times · Source

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();
        }
    });

Answer

pipwerks picture pipwerks · Jun 21, 2016

Unfortunately, PDFObject is not capable of hiding the print button, it only provides a mechanism for specifying PDF Open Parameters, which do not include the ability to hide the print button.

I'm no expert on PDF.js, but since it's all JS-based, and hosted on your domain (i.e. you have full script access), you should be able to find a way to hack it to remove the print button. Good luck!