繁体   English   中英

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

[英]How to load a password protected PDF form using PDFBOX

如何使用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();
    } 
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM