Is it possible to set net.sf.jasperreports.export.pdf.user.password property dinamically

Hello,

 

I have a requirement from users to encrypt the PDF files generated based on the result of one query.

The password should be set dynamically based on the value returned by a query.

Is it possible ? And if yes this would be good if example can be shared.

Thanks,

Frederic

ffranco_1's picture
Joined: Apr 9 2023 - 1:57pm
Last seen: 1 min 22 sec ago

1 Answer:

Frederic,

Maybe this is the best information for u:  https://jasperreports.sourceforge.net/sample.reference/pdfencrypt/index....

example

JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outFile));
 
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);

hope to help u ,
whatClasss

szy.ly's picture
32
Joined: Apr 7 2023 - 9:13pm
Last seen: 4 months 3 weeks ago
Feedback
randomness