Setting JasperReports document properties

Problem Statement:  How to set JasperReports document properties?


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

Reference: Check
1. Jasper Reports API:
2. Jasper Reports Forum
3. Samples:



Leave a Reply

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

You are commenting using your 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