aspose file tools*
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
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Setting Password to PDF ClassCastException Problem" Watch "Setting Password to PDF ClassCastException Problem" New topic
Author

Setting Password to PDF ClassCastException Problem

Vivek Nikam
Greenhorn

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
itextpdf-5.2.0.jar,
commons-collections-3.2.1.jar,
commons-beanutils-1.8.2.jar,
commons-javaflow-20060411.jar,
commons-logging-1.1.jar,
jasperreports-4.5.0.jar,
commons-digester-1.7.jar,
groovy-all-1.7.5.jar,
classes12.jar
iText-2.1.7.jar


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));
exporter.exportReport();

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