atmaling Posted September 3, 2010 Share Posted September 3, 2010 Hi,How to create password protected PDF ?? I tried following code but got the Exception as : java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1OctetString JasperReport jr=JasperCompileManager.compileReport("E:\\report1.jrxml"); JasperPrint jp=JasperFillManager.fillReport(jr,new HashMap(),connection); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_FILE,new File("E:\\report1.pdf")); exporter.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "hi"); exporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, "hi"); exporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE); exporter.exportReport(); I am using "iText-2.1.0.jar" , "jasperreports-3.6.0.jar" .NOt getting more help from anywhere. Plzz help me.Thanks in Advance Link to comment Share on other sites More sharing options...
atharindhi Posted September 3, 2010 Share Posted September 3, 2010 U are missing a another jar file..Might be 2 or 3 jars..Did u include clover.jar fileInclude dat jar and try again..If u get an error againTry to find jar files in www.findjar.comU have all the jars u need there and u can donload as well..Following link will explain u more about user password..I also finding more about this issue more..Im finding a way to restric user to print the PDF for specific number fo time. If u have an idea let me know...Following code will help u to comlete your task..Plz give me KARMA points if this helpfull.http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRPdfExporterParameter.html#IS_ENCRYPTED import net.sf.jasperreports.engine.export.JRPdfExporter;import net.sf.jasperreports.engine.export.JRPdfExporterParameter;import com.lowagie.text.pdf.PdfWriter;........JRPdfExporter exp = new JRPdfExporter();exp.setParameter(JRPdfExporterParameter.IS_128_BIT_KEY, Boolean.TRUE);exp.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE);exp.setParameter(JRPdfExporterParameter.USER_PASSWORD, "user_pwd");exp.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "owner_pwd");Post Edited by atharindhi at 09/03/2010 12:19 Link to comment Share on other sites More sharing options...
atmaling Posted October 14, 2010 Author Share Posted October 14, 2010 Thanks,It worked for me.bcprov-jdk16-145.jar file was missing, downloaded from http://www.bouncycastle.org/latest_releases.htmlInclude jar file in lib or classpath folder.Below is the list of all required jarsjasperreports-3.7.0.1.jarcommons-io-1.3.1.jarcommons-logging-1.0.4.jarcommons-collections-3.2.jarcommons-digester-1.7.jarcommons-beanutils-1.8.0.jargroovy-all-1.5.5.jaritext-2.1.0.jarbcprov-jdk16-145.jar Code: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:atm","uid","pwd"); HashMap hm=new HashMap();JasperReport jr=JasperCompileManager.compileReport("E:\\Atmaling\\my_programs\\pwdReport.jrxml"); JasperPrint jp=JasperFillManager.fillReport(jr,new HashMap(),con); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_FILE,new File("E:\\Atmaling\\my_programs\\pwdReport.pdf")); exporter.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "hi"); exporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, "hi"); exporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE); exporter.exportReport(); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now