Jump to content
We've recently updated our Privacy Statement, available here ×

Password protected PDF


atmaling

Recommended Posts

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

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

U are missing a another jar file..
Might be 2 or 3 jars..
Did u include clover.jar file
Include dat jar and try again..
If u get an error again

Try to find jar files in www.findjar.com

U 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

  • 1 month later...

Thanks,

It worked for me.

bcprov-jdk16-145.jar  file was missing, downloaded from  http://www.bouncycastle.org/latest_releases.html

Include jar file in lib or classpath folder.

Below is the list of all required jars

jasperreports-3.7.0.1.jar
commons-io-1.3.1.jar
commons-logging-1.0.4.jar
commons-collections-3.2.jar
commons-digester-1.7.jar
commons-beanutils-1.8.0.jar
groovy-all-1.5.5.jar
itext-2.1.0.jar
bcprov-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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...