怎么在服务器端使用Adobe reader 在线阅读PDF文件时候屏蔽掉打印、下载工具栏

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么在服务器端使用Adobe reader 在线阅读PDF文件时候屏蔽掉打印、下载工具栏相关的知识,希望对你有一定的参考价值。

参考技术A import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfEncryptor;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;

publicclass PdfHandle
publicvoid hideBars(String inputFile,String outFile)

//复制一个PDF
try
// 创建一个reader
PdfReader reader = new PdfReader(inputFile);
int n = reader.getNumberOfPages();
// 得到第一页
Rectangle psize = reader.getPageSize(1);
float width = psize.height();
float height = psize.width();

// step 1: 创建一个document对象
Document document = new Document(new Rectangle(width, height));
// step 2: 创建一个write
PdfCopy writer = new PdfCopy(document, new FileOutputStream(outFile));
//设置隐藏菜单栏和工具栏
writer.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideToolbar);

// step 3: 打开 document
document.open();
// step 4: 一页一页添加内容
int i = 0;
while (i < n)
document.newPage();
i++;
PdfImportedPage page1 = writer.getImportedPage(reader, i);
writer.addPage(page1);


// step 5: 关闭document

document.close();

catch (Exception de)
de.printStackTrace();


publicvoid notAllowPrint(String inputFile,String outFile)

try
PdfReader reader = new PdfReader(inputFile);
//设置加密权限
PdfEncryptor.encrypt(reader,
new FileOutputStream(outFile),
null,
null,
PdfWriter.AllowAssembly |PdfWriter.AllowFillIn|PdfWriter.AllowScreenReaders,
false);

catch(Exception e)
e.printStackTrace();


publicstaticvoid main(String args[])

PdfHandle pp=new PdfHandle();
pp.hideBars("e://3.pdf", "e://4.pdf");
pp.notAllowPrint("e://4.pdf", "e://5.pdf");



以上程序测试过没有问题。使用时要加入itext.jar到工程里面。
方法1.去掉工具栏。这个很简单。
方法2.屏蔽打印,这个方法其实屏蔽了很多权限,可以在文档中查到。Encrypt方法的第5个参数是受权参数,如果希望用户有什么权限则在这里面定义。如果第三个第四个参数里面定义了密码则用户打开文档就必须输入密码,如果授权为允许打印有定义了密码则不会达到我们单纯屏蔽打印按钮的目的。
权限由如下几种:
AllowPrinting
AllowModifyContents
AllowCopy
AllowModifyAnnotations
AllowFillIn
AllowScreenReaders
AllowAssembly
AllowDegradedPrinting本回答被提问者采纳
参考技术B psize.getHeight();
maven依赖:
<!-- https://mvnrepository.com/artifact/com.lowagie/itext -->
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>

adobe reader 9.4.4mui是干嘛用的,可不可以删 了?

这是一个pdf阅读软件,可以删除。删除对于电脑系统没有任何影响,而且它占用的空间比较大,如果电脑空间余地紧张删掉则更好。不过,删除之后,就无法打开看pdf文件了,如果需要,可以找一款容量小得多、免安装的pdf阅读器软件替代。 参考技术A 这个是查看PDF格式文件用得,删掉对电脑一点问题都不会有。如果你以后要阅读PDF文件了,再装一个小些的(1M多些)PDF阅读器就可以了本回答被提问者采纳 参考技术B Adobe Reader 是用于打开和使用在 Adobe Acrobat 中创建的 Adobe PDF 的工具。 虽然无法在 Reader 中创建 PDF,但是可以使用 Adobe Reader 查看、打印和管理 PDF。在 Reader 中打开 PDF 后,可以使用多种工具快速查找信息。如果您收到一个 PDF 表单,则可以在线填写并以电子方式提交。如果收到审阅 PDF 的邀请,则可使用注释和标记工具为其添加批注。使用 Reader 的多媒体工具可以播放 PDF 中的视频和音乐。如果 PDF 包含敏感信息,则可利用数字身份证或数字签名对文档进行签名或验证
9.4.0是其版本号
其它问题参考:
追问

那我要是删了,是不是就打不开PDF文件了呀?这个PDF文件常用嘛?

参考技术C ky追问

这是干嘛用的呀,原来电脑里好像没有,现在多了700多M呢。
不知道干嘛去的

以上是关于怎么在服务器端使用Adobe reader 在线阅读PDF文件时候屏蔽掉打印、下载工具栏的主要内容,如果未能解决你的问题,请参考以下文章

Adobe acrobat reader 的最新版本是啥 win7 64位的

adobe reader 9.4.4mui是干嘛用的,可不可以删 了?

C#winform adobe PDF reader 控件

用adobe reader 打开一个pdf文档,点击了文档里链接到本文档的链接,如何回到上一个位置

Adobe Reader来填写的表单无法保存,我怎么做pdf表单才能使别人可以用Adobe Reader来填写的表单能保存

Adobe Acrobat Reader DC不能同时打开两个PDF的问题