如何在生成的PDF文件中禁用打印选项? [英] How to disable options as printing in generated PDF file?

查看:165
本文介绍了如何在生成的PDF文件中禁用打印选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我生成带有jasper报告的PDF时,我不希望用户能够打印它.

When I generate a PDF with jasper reports I don't want the user to be able to print it.

是否可以从代码中进行选择,还是仅依赖于可视化程序(Web浏览器,adobe等).

Is there some option to make it from the code or does it only depend on the program which visualize it (web browser,adobe etc.).

推荐答案

您可以通过使用jrxml属性或将值设置为

You can achive this both by using jrxml properties or setting values to the SimplePdfExporterConfiguration if you are exporting from java.

要保护您的pdf文档(在这种情况下,不允许打印),首先要做的是对其进行加密,并确保在类路径中具有用于加密的必要的库,请参见

To protected your pdf document (hence in this case disallow printing), first thing you need to do is to encrypt it and be sure that you have nessary libraries for encryption in classpath see How to configure PDF encryption in JasperReports Server 5.6.1

jrxml属性

<property name="net.sf.jasperreports.export.pdf.encrypted" value="true"/>
<property name="net.sf.jasperreports.export.pdf.128.bit.key" value="true"/>
<property name="net.sf.jasperreports.export.pdf.owner.password" value="12345"/>

Java代码

SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setEncrypted(true);
configuration.set128BitKey(true);
configuration.setOwnerPassword("1234"); 

请注意,我们设置的所有者密码不是用户密码,因此允许用户打开而无需密码.

Note we are setting owner password not user password, hence user will be allowed to open without.

现在设置用户权限

net.sf.jasperreports.export.pdf.permissions.allowed

在您的情况下,我猜您只希望允许屏幕阅读器,如果您还希望允许COPY或其他操作(请参见上面的链接),请在属性中添加|

In your case I guess you only like to allow screen readers, if you like to also allow COPY or other actions (see link above) add these with | to your properties

jrxml属性

<property name="net.sf.jasperreports.export.pdf.permissions.allowed" value="SCREENREADERS"/>

Java代码

configuration.setPermissions(PdfWriter.ALLOW_SCREENREADERS);

注意::阅读器/应用程序应尊重许可,因此开发人员可以随时打开任何PDF文档并执行所需的操作.例如,iText包含一个标记unethicalreading,如果将其设置为true,您将可以使所有者在不知道密码的情况下访问这些文档.

Notice: it is up to the reader/application to respect the permission, hence a developer can always open and do what they want with any PDF document. As example iText contains a flag unethicalreading, if you set it to true, you will be able to have owner access to these documents without knowing the password.

这篇关于如何在生成的PDF文件中禁用打印选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆