我正在尝试通过PDFRenderer库在java程序中打开加密的pdf文件。编译代码时,给 PDFPassword 类错误。这是我代码的一部分。
RandomAccessFile raf = new RandomAccessFile(new File(filename), "r");
FileChannel fc = raf.getChannel();
ByteBuffer buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
String password = "58e72df9-0";
try{
PDFPassword pass = new PDFPassword(password);
//System.out.println(PDFPassword.nonNullPassword(pass));
PDFFile pdffile = new PDFFile(buf, pass);
我得到的错误是:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.sun.pdfview.decrypt.PDFPassword$PDFDocEncodingByteGenerator.createCharsetEncoder(PDFPassword.java:256)
at com.sun.pdfview.decrypt.PDFPassword$CharsetEncoderGenerator.generateBytes(PDFPassword.java:222)
at com.sun.pdfview.decrypt.PDFPassword.generatePossiblePasswordBytes(PDFPassword.java:167)
at com.sun.pdfview.decrypt.PDFPassword.getPasswordBytes(PDFPassword.java:111)
at com.sun.pdfview.decrypt.StandardDecrypter.<init>(StandardDecrypter.java:159)
at com.sun.pdfview.decrypt.PDFDecrypterFactory.createStandardDecrypter(PDFDecrypterFactory.java:316)
at com.sun.pdfview.decrypt.PDFDecrypterFactory.createDecryptor(PDFDecrypterFactory.java:99)
at com.sun.pdfview.PDFFile.readTrailer(PDFFile.java:1051)
at com.sun.pdfview.PDFFile.parseFile(PDFFile.java:1175)
at com.sun.pdfview.PDFFile.<init>(PDFFile.java:126)
at pdfview.pdfView.main(PdfView.java:49)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -128
at com.sun.pdfview.PDFDocCharsetEncoder.<clinit>(PDFDocCharsetEncoder.java:68)
... 11 more
我不确定你的问题,但也:
如果你使用这个库,它有递归调用自己的加密错误。
我有加密问题,这是堆栈溢出。我发现了问题,它解决了堆栈溢出问题。像这样更改密码类
也许这可以解决您的问题