0

使用 pdf.js 渲染文件时,我正在尝试打印按钮和其他按钮。我尝试使用 CSS,它适用于 Chrome,但不适用于 Internet Explorer。对于 Internet Explorer,我使用了 javascript。当我加载一个文件但后续文件仍显示按钮时,JS 工作。

查看器.html

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

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

查看器.css

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

默认.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();
        }
    });
4

4 回答 4

1

我在这里在黑暗中拍摄,因为我不知道 PDF 查看器是否加载<iframe>,但下面的代码将无限期地扫描页面并禁止显示打印按钮是否找到它。

    var $printSearch = setInterval(function() {
      if ($('#print').length > 0 || $('#print').is(':visible')) {
        hidePrint();
      } else {
        //doNothing
        console.log('Searching...');
      }
    }, 150);

    function hidePrint() {
      $('div#print').css('display', 'none');
    }

如果它确实在 iframe 中加载,我们可以使用.contents().filter()jQuery 方法来定位那些难以捉摸的按钮。

于 2016-06-21T20:58:33.760 回答
1

不幸的是,PDFObject 不能隐藏打印按钮,它只提供了一种指定 PDF 打开参数的机制,不包括隐藏打印按钮的能力。

我不是 PDF.js 方面的专家,但由于它都是基于 JS 的,并且托管在您的域上(即您拥有完整的脚本访问权限),您应该能够找到一种方法来破解它以删除打印按钮。祝你好运!

于 2016-06-21T07:11:33.603 回答
0

通过处理 PDF.js 提供的 pagerendered 事件,我能够隐藏按钮。

查看器.html

<script type="text/javascript">
    $(function () {
        document.addEventListener("pagerendered", function (e) {
            $('#print').hide();
            $('#viewBookmark').hide();
            $('#openFile').hide();
        });
    });
</script>
于 2016-06-21T18:09:28.303 回答
-2

您是否尝试过使用印刷媒体查询?

于 2016-06-20T21:02:38.020 回答