Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
628 views
in Technique[技术] by (71.8m points)

jasper reports - How to disable options as printing in generated PDF file?

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

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.).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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 properties

<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"/>

or

java code

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.

Now set the user permissions

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

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

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

or

java code

configuration.setPermissions(PdfWriter.ALLOW_SCREENREADERS);

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...