Setting JasperReports document properties

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-

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s