This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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(
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(
at PDFPassword.main(

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:
subject: Setting Password to PDF ClassCastException Problem
It's not a secret anymore!