wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes Setting Password to PDF ClassCastException Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Setting Password to PDF ClassCastException Problem" Watch "Setting Password to PDF ClassCastException Problem" New topic

Setting Password to PDF ClassCastException Problem

Vivek Nikam

Joined: Aug 27, 2011
Posts: 5
While setting password to PDF, I am getting following error
Exception in thread "Main Thread" java.lang.ClassCastException: java.lang.String
at net.sf.jasperreports.engine.JRAbstractExporter.setInput(JRAbstractExporter.java:858)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:259)
at PDFPassword.main(PDFPassword.java:116)

so can you please help me? Please

I am using Eclipse.

I have included all related jars in path

JasperDesign jasperDesign = JRXmlLoader.load("Path of jrxml file");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Map parameters = new HashMap();
parameters.put("EMPNO", "7369");
Connection conn = DataBase.getConnection();

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
JasperExportManager.exportReportToPdfFile(jasperPrint,"Path for PDF file");

JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.INPUT_FILE,"Path for PDF file");
exporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE);
exporter.setParameter(JRPdfExporterParameter.IS_128_BIT_KEY, Boolean.TRUE);
exporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, "jasper");
exporter.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "reports");
exporter.setParameter(JRPdfExporterParameter.PERMISSIONS, new Integer(PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING));

PDF file is generated at Specified Location as mentioned in JasperExportManager.exportReportToPdfFile() but it is not password protected,
when code executed exporter.exportReport(); generates this exception. So password is not set to PDF.
I am getting same error while generating report in Text format using JRTextExporter.
Please help me.
I agree. Here's the link: http://aspose.com/file-tools
subject: Setting Password to PDF ClassCastException Problem