![](/img/trans.png)
[英]Why password protected PDF using PDFBOX is opening without password in Microsoft Edge browser?
[英]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.