Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Password to PDF ClassCastException Problem

 
Vivek Nikam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic