Setting JasperReports document properties
March 1, 2010
Leave a comment
Problem Statement: How to set JasperReports document properties?
Solution:
net.sf.jasperreports.engine.JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter(); // Properties Begin exporter.setParameter( JRPdfExporterParameter.METADATA_TITLE, "Title of the Document" ); exporter.setParameter( JRPdfExporterParameter.METADATA_AUTHOR, "Author of the document" ); exporter.setParameter( JRPdfExporterParameter.METADATA_SUBJECT, "Subject line of document" ); exporter.setParameter( JRPdfExporterParameter.METADATA_KEYWORDS, "Key Words to search down the line" ); exporter.setParameter( JRPdfExporterParameter.METADATA_CREATOR, "Application Name, which created this document." ); exporter.setParameter( JRPdfExporterParameter.OUTPUT_FILE_NAME, "Used when click on save button from client" ); //This used to set document passwords and compression and encryption JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_USER_PASSWORD, "password1" ); JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_OWNER_PASSWORD, "password2" ); JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_ENCRYPTED, true ); JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_COMPRESSED, true ); ByteArrayOutputStream out = new ByteArrayOutputStream(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out); exporter.exportReport();
Reference: Check
1. Jasper Reports API: http://jasperreports.sourceforge.net/api/index.html
2. Jasper Reports Forum
3. Samples: http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/samples.html
-o-



