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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…