我想用JasperReports和Java生成密码保护的PDF文件。受密码保护的PDF Jaspersoft
代码如下:
jrPdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, path.concat(filename).concat(".pdf"));
jrPdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jprint);
jrPdfExporter.setParameter(JRPdfExporterParameter.OWNER_PASSWORD, "Bancosol123");
jrPdfExporter.setParameter(JRPdfExporterParameter.USER_PASSWORD, "Bancosol123");
jrPdfExporter.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE);
jrPdfExporter.exportReport();
我利用iText 2.1.7生成PDF,它工作正常,但是当我包括密码的一部分,我得到了错误
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.DEREncodable
我包括以下两个jar:
bcprov-jdk15on-1.47.jar
bcmail-jdk15on-1.47.jar
但问题仍未解决。我读的地方它可能是一个兼容性问题的iText 2.1.7
所以我删除的iText 2.1.7,其中包括的iText 5.3.2
现在我有以下错误
exception in thread "awt-eventqueue-0" java.lang.noclassdeffounderror: com/lowagie/text/documentexception
为什么iText 5.3.2而不是iText 5.5.12? –
'java.lang.noclassdeffounderror:com/lowagie/text/documentexception':这是可以预料的。您需要在所有导入语句中将'com.lowagie'替换为'com.itextpdf'。 –
_I read somewhere_ - 你在哪里读过的?编辑您的文章并添加链接。 –