【问题标题】:Disable copy and print options in pdf viewer禁用 pdf 查看器中的复制和打印选项
【发布时间】:2017-07-27 10:47:34
【问题描述】:

我使用标签来显示文档(文件)。在显示 pdf 文件时带有打印和下载选项,我需要删除 pdf 查看器中的打印和下载选项,有什么方法可以隐藏它。

下面是我查看pdf文档的html代码

<iframe class="iframemargins" src="{{ url('uploads/chapters/Author.pdf') }}" 
        title="PDF in an i-Frame" frameborder="0" scrolling="auto" width="100%" 
        height="600px">
</iframe>

还有其他方式可以显示pdf、doc、txt、rtf等文件吗?

【问题讨论】:

    标签: html css


    【解决方案1】:

    我在此找到了解决方案...这是我获得解决方案的链接

    Hiding the toolbars surrounding an embedded pdf?

    我已经更新了我的 html 代码,如下所示,它的工作原理

    <iframe src="{{ url('uploads/chapters/Author.pdf') }}#toolbar=0&navpanes=0&scrollbar=0" title="PDF in an i-Frame" frameborder="0" scrolling="auto" style="width:100%; height:100%;"></iframe>
    

    【讨论】:

    • 但是 toolbar=0 也会禁用书签和页码功能。是不是。只禁用打印和下载按钮怎么样?
    • 当您在浏览器上右键单击文档并允许保存文档或在其他应用程序上打开它时,是否会禁用上下文菜单?
    【解决方案2】:

    您可以使用打印媒体查询来隐藏打印中的元素。请参阅下面的示例。

    var btn = document.getElementById("print");
    btn.addEventListener("click", function(){
        window.print();
    });
    @media print {
        .print {
            display: none;
        }
    }
    <h3 style='text-align: center'>My Table</h3>
    <table border='1' style='border-collapse: collapse; width: 100%;'>
    <thead>
      <tr>
        <th>Heading 1</th>
        <th>Heading 2</th>
        <th>Heading 3</th>
      </tr>
    </thead>
    <tbody>
        <tr>
        <th>Value 1</th>
        <th>Value 2</th>
        <th>Value 3</th>
      </tr>
        <tr>
        <th>Value 1</th>
        <th>Value 2</th>
        <th>Value 3</th>
      </tr>
        <tr>
        <th>Value 1</th>
        <th>Value 2</th>
        <th>Value 3</th>
      </tr>
        <tr>
        <th>Value 1</th>
        <th>Value 2</th>
        <th>Value 3</th>
      </tr>
    </tbody>
    </table>
    <button class='print'>Download</button>
    <button class='print' id='print'>Print</button>

    【讨论】:

    • 这不是我想要的,实际上我需要使用 iframe 标签显示没有打印和下载选项的 pdf 文件
    • 你的意思是隐藏浏览器打印预览的下载和打印选项?
    • 不,在 html 元素中使用 iframe 的文档查看器
    【解决方案3】:

    使用为您提供 PDF 查看器源的PDF.js。只需从web/viewer.html 中删除这些按钮即可。

    请注意,您的 URL 必须按照指定的 here 更改为 web/viewer.html?file={{ url('uploads/chapters/Author.pdf') }}


    要查看 MS Office 文档,请使用类似 Zoho

    【讨论】:

    • 如何使用pdf.js文件我需要文档
    • @Vinothini 不要直接链接到 PDF 本身,而是使用 file 参数将 iframe 链接到您的 viewer.html 页面
    • 我已经发布了我的答案,见下文
    • @Vinothini 适用于 MS Office - Zoho Docs,适用于简单文件 - PHP 中的 file_get_contents
    • 如何在前端查看文件,这样我就必须使用html才知道?
    猜你喜欢
    • 1970-01-01
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 2021-05-06
    相关资源
    最近更新 更多