Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/402.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使用用户密码解密受保护的pdf_Java_Itext - Fatal编程技术网

Java 通过itext使用用户密码解密受保护的pdf

Java 通过itext使用用户密码解密受保护的pdf,java,itext,Java,Itext,通过itext解密带有用户密码的受保护pdf时。在控制台中显示为用法: PdfContentReaderTool <pdf file> [<output file>|stdout] [<page num>] PdfContentReaderTool[|标准输出][] “帮助”我是itext的新手,您可以参考此代码,在我的情况下它工作正常: public class PDFUtils { public static final String SO

通过itext解密带有用户密码的受保护pdf时。在控制台中显示为用法:

PdfContentReaderTool <pdf file> [<output file>|stdout] [<page num>] 
PdfContentReaderTool[|标准输出][]

“帮助”我是itext的新手,您可以参考此代码,在我的情况下它工作正常:

public class PDFUtils {

    public static final String SOURCE_FILE = "encrypted.pdf";
    public static final String DESTINATION_FILE = "decrypted.pdf";

    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DESTINATION_FILE );
        file.getParentFile().mkdirs();
        new PDFUtils ().decryptPdf(SOURCE_FILE , DESTINATION_FILE );
    }

    public void decryptPdf(String srcFile, String destFile) throws IOException, DocumentException {
        PdfReader reader = new PdfReader(srcFile, "XXX".getBytes());
        System.out.println(new String(reader.computeUserPassword()));
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(destfile));
        stamper.close();
        reader.close();
    }
}

您使用什么代码进行解密?PdfReader reader=newpdfreader(“D:/Sample1.pdf”,“password.getBytes());PdfStamper stamper=新PdfStamper(读取器,新文件输出流(“/NoPasswordPDF.pdf”);压模关闭();reader.close();当前iText 5.5.x中没有“PdfContentReaderTool”类或字符串,因此输出不是某些iText类的输出。可能是您创建的某个工具,它被初始化为一个副作用,或者您使用了被操纵的iText JAR。正如您后续的问题所表明的,您的问题根本不是由iText引起的。可能您只是启动了错误类的
main
method`。用法:pdfcontentreaderdtool[| stdout][]仍会收到相同的错误。