我想通过java itext制作受密码保护的pdf。这个代码我从网上获得。
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();
}
}
}
他们说运行代码我需要这些jar文件 -
•itextpdf-5.2.1.jar
•bcmail-jdk16-1.46.jar
•bcprov-jdk16-1.46.jar
•bctsp-jdk16-1.46.jar
我添加了这个,但每次都有 - 线程中的异常" main" java.lang.NoClassDefFoundError:org / bouncycastle / asn1 / ASN1Primitive 如何成功运行我的代码?