I want to make a password protected pdf by java itext. This code I get from net .
public class GeneratePDF
{
private static String USER_PASS = "Hello123";
private static String OWNER_PASS = "Owner123";
public static void main(String[] args) {
try {
OutputStream file = new FileOutputStream(new File("D:\\Test.pdf"));
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, file);
writer.setEncryption(USER_PASS.getBytes(), OWNER_PASS.getBytes(),
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);
document.open();
document.add(new Paragraph("Hello World, iText"));
document.add(new Paragraph(new Date().toString()));
document.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
They said to run the code I need these jar files-
• itextpdf-5.2.1.jar
• bcmail-jdk16-1.46.jar
• bcprov-jdk16-1.46.jar
• bctsp-jdk16-1.46.jar
I add this , but every time there is - Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Primitive How can I successfully run my code ?