• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java program to password protect a signed pdf file

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read this.
 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic