Java 如何使用PDFBOX加载受密码保护的PDF表单

Java 如何使用PDFBOX加载受密码保护的PDF表单,java,pdfbox,Java,Pdfbox,如何使用PDFBOX加载受密码保护的PDF表单 我有一小段代码来加载不受保护的PDF表单 PDDocument pdfDoc; pdfDoc = PDDocument.load(filePath); 有人能帮我吗。。 谢谢请尝试以下代码: private void openPDFDoc(final File pdfFile) throws Exception { File originalPDF = pdfFile; PDFParser parser =

如何使用PDFBOX加载受密码保护的PDF表单

我有一小段代码来加载不受保护的PDF表单

  PDDocument pdfDoc;
  pdfDoc = PDDocument.load(filePath);
有人能帮我吗。。
谢谢

请尝试以下代码:

private void openPDFDoc(final File pdfFile) throws Exception {
        File originalPDF = pdfFile;
        PDFParser parser = new PDFParser(new BufferedInputStream(new FileInputStream(
                originalPDF)));
        parser.parse();

        PDDocument originialPdfDoc = parser.getPDDocument();

        boolean isOriginalDocEncrypted = originialPdfDoc.isEncrypted();
        if (isOriginalDocEncrypted) {
            originialPdfDoc.openProtection(new StandardDecryptionMaterial("password"));
        }
    }
你可以用

public static void main(String[] args){
PDDocument pd;
try {
     File input = new File("p.pdf");  // password protected PDF file from where you would like to extract
     pd = PDDocument.load(input,"your_password");
     pd.setAllSecurityToBeRemoved(true);

     //for printing pdf file data
     PDFTextStripper reader = new PDFTextStripper();
     String pageText = reader.getText(pd);
     System.out.println(pageText);
     } catch (Exception e){
     e.printStackTrace();
    } 
 }

令人惊叹的。。。它的工作。。。感谢您的快速响应@SAN3为什么加密文档文本提取比正常提取慢得多?慢5~10倍。还有什么需要加速的吗?