how to password protect a pdf
DESCRIPTION
Describes how to password protect a pdfTRANSCRIPT
How to password protect a pdf.Steps.1. To password protect a pdf java has a simple class called pdfencryptor which has a procedure called encrypt. The format of the procedure is given below.public static void encrypt(PdfReader reader, OutputStream os, byte userPassword[], byte ownerPassword[], int permissions, boolean strength128Bits)
* param reader is the PDF file which is to be password protected * param os is the output destination
* param userPassword is the user password. Can be null or empty(This is the main password
which has to be set.) * param ownerPassword is the owner password. Can be null or empty
* param permissions are the user permissions(Like allow printing, allow copy etc.) * param strength128Bits true for 128 bit key length, false for 40 bit key length This can be more clear by the following example. To use the above procedure in the code one
must write the following into his or her code.PdfEncryptor.encrypt(test.pdf, new FileOutputStream("C:/pdf encryption/Outfile.pdf"), Hello .getBytes(), null,PdfWriter.AllowPrinting | PdfWriter.AllowCopy, false);2. Download iText-5.0.4.jar from internet and add it to the library . Otherwise the above code cannot be compiled.