简体   繁体   中英

Is it possible to set only owner password while using setEncryption method in iText?

Is it possible to set owner password as some value and user password as null or empty while using set encryption method of PdfWriter class?

I tried using code something like this

 String OWNER = "test";
 PdfWriter.setEncryption(null,OWNER.getBytes(),
                        PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);

I am able to open PDF generated with this code without entering any password. BUT when I try to open it for editing with Adobe Acrobat, it opens the document in view mode and throws an error "This is secured document. Editing is not permitted." Screenshot of error: http://dropbox.com/s/1ef551o1z0n9ug1/editerror.jpg

Any idea why this must be occurring? Am I doing something wrong?

On an additional note,

I have generated this new document with

PdfWriter.setEncryption("test1".getBytes(),"test".getBytes(), 
                        PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128); 

Link: http://dropbox.com/s/8jeia7ezervrz18/Test_Success.pdf

I am able to view it after entering password as "test1" and able to edit it with password "test". I am not sure what exactly is going wrong when I pass USER as null in earlier case.

I am using following set of jars in my project

  • itext-2.1.7.jar
  • bcmail-jdk14.jar
  • bcprov-jdk14.jar
    private static String user = "";
    private static String admin = "ADMIN";      
writer.setEncryption(admin.getBytes(), user.getBytes(),
                PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);

By using the above approach you can set admin password. There might be some problem in your classpath setting. Use Mavel on Gardle for dependencies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM