| Author |
java program to password protect a signed pdf file
|
pavithra murthy
Ranch Hand
Joined: Feb 06, 2009
Posts: 53
|
|
hello ,
i am trying to password protect a signed pdf file using jPDFSecure api and also making use of jPDFSecure.jar file .
but in this program i am getting an error when i am trying to set the permissions in setSecurity method . Please could anyone help me
the error i am getting is
D:\>javac SetPermissions.java
SetPermissions.java:24: setSecurity(java.lang.String,java.lang.String,com.qoppa.
pdf.PDFPermissions,java.lang.String,int) in com.qoppa.pdfSecure.PDFSecure cannot
be applied to (java.lang.String,java.lang.String,com.qoppa.pdf.PDFPermissions,<
nulltype>)
pdfSecure.setSecurity("owner", "user", perms, null);
^
1 error
|
 |
Moojid Hamid
Ranch Hand
Joined: Mar 07, 2009
Posts: 120
|
|
|
Look at the signature of the method you are calling, in your method call you are missing the last parameter of type int.
|
 |
pavithra murthy
Ranch Hand
Joined: Feb 06, 2009
Posts: 53
|
|
hi ,
thanks a lot . i gave the int parameter but when i run the program even password correctly entered is not opening the pdf file
It is asking for the password but its giving a message "There was an error opening this document .Bad Encrypt Dictionary"
please could you help me out
But the last parameter is expected to be an integer ..so i gave like 777
|
 |
Moojid Hamid
Ranch Hand
Joined: Mar 07, 2009
Posts: 120
|
|
|
For that last parameter you can either specify RC4, or AES. AES only works for newer versions of acrobat reader, you can either use RC4 or update to a newer version of acrobat reader.
|
 |
pavithra murthy
Ranch Hand
Joined: Feb 06, 2009
Posts: 53
|
|
But the last parameter is expected to be an integer ..so i gave like 777
pdfSecure.setSecurity("owner", "user", perms, null,777);
Is it correct ?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56229
|
|
|
Please read this.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Moojid Hamid
Ranch Hand
Joined: Mar 07, 2009
Posts: 120
|
|
Have a look at the Java Doc.
encryptType - - The encryption type to use, this value can be either PDFPermissions.ENCRYPTION_RC4 or PDFPermissions.ENCRYPTION_AES.
|
 |
pavithra murthy
Ranch Hand
Joined: Feb 06, 2009
Posts: 53
|
|
pdfSecure.setSecurity(null, "user", perms, null,PDFPermissions.ENCRYPTION_AES);
hi tried with the above command .now its working but
the signature is becoming invalid in the locked signed document ..
i had written another java code for digital signing on pdf using itext . the output signed pdf document from this code which i got as output ...now i am trying to password protect it .
Signed pdf document is opening but the signature is becoming invalid . please could you help me out
|
 |
Moojid Hamid
Ranch Hand
Joined: Mar 07, 2009
Posts: 120
|
|
|
instead of using pdfSecure try the setEncription methods of pdfStamper, that way you can sign and lock using same pdfStamper (stp) object.
|
 |
pavithra murthy
Ranch Hand
Joined: Feb 06, 2009
Posts: 53
|
|
hi
i tried with the old itext code according to the syntax but its giving out an error
E:\>javac pdfsignencryption.java
pdfsignencryption.java:39: cannot resolve symbol
symbol : variable STANDARD_ENCRYPTION_128
location: class pdfsignencryption
PdfStamper.setEncryption(STANDARD_ENCRYPTION_128
,"owner","user",777);
^
pdfsignencryption.java:39: non-static method setEncryption(boolean,java.lang.Str
ing,java.lang.String,int) cannot be referenced from a static context
PdfStamper.setEncryption(STANDARD_ENCRYPTION_128
,"owner","user",777);
^
2 errors
syntax of setEncryption i got it from this link
http://1t3xt.info/api/com/lowagie/text/pdf/PdfStamper.html#setEncryption(int,%20java.lang.String,%20java.lang.String,%20int)
|
 |
Moojid Hamid
Ranch Hand
Joined: Mar 07, 2009
Posts: 120
|
|
Well, both error messages are self-explanatory: first one is telling you that it cannot find that constant that you are referring to (you need to qualify it with the class/interface name it is defined in). Second error message is telling you that the method is not static method, you need an object of type PdfStamper before you can call this method (remember stp object?)
IMHO, what it shows is that you need to get up to speed with java basics, copy pasting code from different sources is not going to take you very far. I am not attempting to be rude, you need to pick-up a good book on java and practice a little, it will help you figure out many things on your own.
This thread seems more suitable for OtherOpenSourceProjects forum.
|
 |
 |
|
|
subject: java program to password protect a signed pdf file
|
|
|