Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)
|
|
|
|
JasperReports - PDF Encrypt Sample (version 4.0.1) | |
|
|
|
Main Features in This Sample | |
| Encrypted PDF |
|
|
||||
top | |||||
|
|||||
Encrypted PDF | Documented by Sanda Zaharia | ||||
|
|||||
| Description / Goal |
| How to produce encrypted PDF reports. | ||
| Since |
| 0.5.1 | ||
|
|||||
|
PDF Encryption
There are situations when documents are supposed to be accessed by authorized users only. Using the file encryption represents a method of protecting a document from unauthorized access. There are two categories of document users: the document owner (which provides full document access granted by default) and regular document users (with limited access permissions. User permissions and document restrictions can be set by the document owner only. To distinguish between these user categories, the document is allowed to store within up to two passwords: an owner password and a user password. The application decides whether to encrypt a document based on the presence of any of these passwords or access restrictions. If they are set, the document will be encrypted, making all its content unreadable to unauthorized users. User permissions and all other information required to validate the passwords will be stored in the document's encryption dictionary. When a user attempts to open an encrypted document protected with a password, a dialog will open prompting for the appropriate password. If the password matches, then all user permissions are activated and the document can be open, decrypted, and displayed in a readable form on the screen. If no password is set, when open the document no password is requested and full access is granted by default. Opening the document with the owner password enables the full access to the document, including the possibility to change passwords and access permissions. Opening the document with the user password enables some additional operations to be performed, with respect to the user access permissions stored in the encryption dictionary. Encrypted PDF in JasperReports When exporting to the PDF format the engine has to know five additional things about the generated document and uses five dedicated exporter parameters for this:
This sample makes use of the above export parameters in order to generate an encrypted document. Taking a look at the pdf() method in the src/PdfEncryptApp.java file, one can see how to set them all:
exporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE); exporter.setParameter(JRPdfExporterParameter.IS_128_BIT_KEY, Boolean.TRUE); exporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, "jasper"); exporter.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "reports"); exporter.setParameter( JRPdfExporterParameter.PERMISSIONS, new Integer(PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING) );Running the Sample Running the sample requires the Apache Ant library. Make sure that ant is already installed on your system (version 1.5 or later).
In a command prompt/terminal window set the current folder to demo/samples/pdfencrypt within the JasperReports source project and run the > ant test view command.
It will generate all supported document types containing the sample report in the demo/samples/pdfencrypt/build/reports directory.
Then the report will open in the JasperReports internal viewer. |
||||
|
|
© 2001-2010 Jaspersoft Corporation www.jaspersoft.com |