若是咱們在用iText 作爲java 爲PDF 文檔加水印的時候 報以下異常 java
java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable com.itextpdf.text.pdf.PdfEncryption.<init>(PdfEncryption.java:147) com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj(PdfReader.java:779) com.itextpdf.text.pdf.PdfReader.readDocObj(PdfReader.java:1156) com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:511) com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:170) com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:159) com.fh.util.SetWarter.setWatermark(SetWarter.java:62) com.fh.util.SetWarter.setpdfWater(SetWarter.java:37) com.fh.controller.Relatedlaw.relatedlaw.RelatedLawController.save(RelatedLawController.java:231) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
或 一下異常:web
com.itextpdf.text.exceptions.BadPasswordException:: PdfReader not opened with owner password (未設置加密密碼) 或是 com.itextpdf.text.exceptions.BadPasswordException: PdfReader not opened with owner passwor (設置正確加密密碼後)
解決方法:spring
首先下載一個jar包: bcprov-jdk15on-1.57.jar加密
將包導入項目中以後, 可能會出現如下異常:spa
com.itextpdf.text.exceptions.BadPasswordException:: PdfReader not opened with owner password (未設置加密密碼)
或是
com.itextpdf.text.exceptions.BadPasswordException: PdfReader not opened with owner passwor (設置正確加密密碼後)
那 咱們的解決方法是 :code
PdfReader reader = new PdfReader(input); reader.unethicalreading = true; // 新加這段代碼, 就能將密碼報錯問題解決