Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Itext 5.5.9-设置加密时出现问题_Java_Itext - Fatal编程技术网

Java Itext 5.5.9-设置加密时出现问题

Java Itext 5.5.9-设置加密时出现问题,java,itext,Java,Itext,我在为pdf设置加密时遇到以下异常 Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Primitive 以下是守则- public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = ne

我在为pdf设置加密时遇到以下异常

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: 
org/bouncycastle/asn1/ASN1Primitive
以下是守则-

public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(src);
    int n = reader.getNumberOfPages();
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));

    HashMap<String, String> info = reader.getInfo();
    info.put("Title", "Accessible Itext PDF");
    info.put("Subject", "Itext PDF");
    info.put("Keywords", "Itext");
    info.put("Creator", "Me");
    info.put("Author", "Me");
    stamper.setMoreInfo(info);
    stamper.setEncryption(USER_PASSWORD.getBytes(),OWNER_PASSWORD.getBytes(), PdfWriter.ALLOW_PRINTING,PdfWriter.ENCRYPTION_AES_128);

    PdfContentByte pagecontent;

    for (int i = 0; i < n; ) {
        pagecontent = stamper.getOverContent(++i);
        ColumnText.showTextAligned(pagecontent, Element.ALIGN_RIGHT,
                new Phrase(String.format("page %s of %s", i, n)), 550, 20, 0);
    }

    stamper.close();
    reader.close();
}        
public void manufacturepdf(String src,String dest)抛出IOException,DocumentException{
PdfReader读取器=新PdfReader(src);
int n=reader.getNumberOfPages();
PdfStamper stamper=新PdfStamper(读取器,新文件输出流(dest));
HashMap info=reader.getInfo();
info.put(“标题”,“可访问的Itext PDF”);
info.put(“主题”、“Itext PDF”);
信息放置(“关键字”、“Itext”);
信息放置(“创建者”、“我”);
信息。放置(“作者”、“我”);
母版。setMoreInfo(信息);
stamper.setEncryption(USER_PASSWORD.getBytes()、OWNER_PASSWORD.getBytes()、PdfWriter.ALLOW_PRINTING、PdfWriter.ENCRYPTION_AES_128);
PdfContentByte页面内容;
对于(int i=0;i

我已经在外部添加了itext 5.5.9、bcprov-jdk16-146、bcmail-jdk16-146、bctsp-jdk16-146 JAR,但我仍然得到了错误

org/bouncycastle/asn1/asn1原语
bcprov-ext-jdk16
的一部分。Dowload将其添加到类路径中,错误就会消失

你可以下载它

好的,我让它工作了


看起来itext 5.5.9 jar有问题。我用itext 5.2.1替换了它,它运行得很好。

@CoolKicks你确定它丢失的是同一个类吗?谢谢@jens..我用itext 5.2.1替换了itext 5.5.9使它运行了,用一个古老的itext 5.2.1替换了相当流行的itext 5.5.9,这是一个巨大的倒退,无论是功能方面还是错误修复方面。这很难说是一个解决方案。我无法使用5.5.9来实现它…你有什么想法吗?根据研究,该版本依赖于Bouncy Castle版本1.49,并且在BC 1.46和BC 1.49之间进行了重大更改。因此,我建议更新您的BC JAR。