有的项目需要显示PDF类的文档, 大多需要在项目中禁止将PDF打印, 下载

我最初采用embed标签显示 PDF, iframe,object标签都可以显示
但是这类标签的打印和下载按钮 不可以禁止, 只能障眼法掩盖,

在这里插入图片描述这种方法虽然可行, 但是顶部栏全部不显示了, 包括PDF的页码
这样使用后, 还有一个头疼的地方, 右键网页中的PDF文档, 依然可以保存, 打印

之后找到PDF.js 插件, 可以禁止下载, 官网下载地址http://mozilla.github.io/pdf.js/
进入后
在这里插入图片描述
点击download
进入下一页面
在这里插入图片描述
选择下载稳定版本, 下载解压后放到pdfjs目录
在这里插入图片描述
pdf.js 使用方便, 只需访问
http://localhost/pdfjs/web/viewer.html?file=pdf文件地址
到这里已经可以成功访问了, 但是当前方法是将pdf新页面展示,
也可以将上面的地址, 放到页面中的
embed或iframe标签中, 就成功将PDF嵌入网页中了,
在这里插入图片描述
pdf.js的下载和打印按钮都可以在web下的viewer.html隐藏, 将print和download 隐藏就可以
在viewer.html中将print和download 隐藏就可以,
还有很重要的一点, 禁止右键下载,打印, 添加如下js代码 ,
注意要添加在插件中的 viewer.html中才有效, 添加在当前embed页面是没用的

<script type="text/javascript">function stop(){return false;}document.oncontextmenu = stop;</script>
GitHub 加速计划 / pd / pdf.js
5
0
下载
PDF Reader in JavaScript
最近提交(Master分支:5 个月前 )
61c3ed47 For images that include SMask/Mask entries, ignore an SMask defined in the current graphics state (bug 986450) 13 天前
20d53320 From section [11.6.4.3 Mask Shape and Opacity](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G10.4848628) in the PDF specification: - An image XObject may contain its own *soft-mask image* in the form of a subsidiary image XObject in the `SMask` entry of the image dictionary (see "Image Dictionaries"). This mask, if present, shall override any explicit or colour key mask specified by the image dictionary's `Mask` entry. Either form of mask in the image dictionary shall override the current soft mask in the graphics state. 14 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐