Tuesday, July 22, 2014

Set Password in PDF in Jasper Report

Following code snip can be used to create protected PDF. This authentication is enabled in jasper report 5.6 onward.

   SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
                
  configuration.setEncrypted(true);
  configuration.set128BitKey(true);
  configuration.setUserPassword("jasper");
  configuration.setOwnerPassword("reports");
  configuration.setPermissions(PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING);
  exporter.setConfiguration(configuration);
  exporter.exportReport(); 

1 comment: