我正在尝试通过 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