我在itext中非常陌生,正在使用7.1.4版,并获得了3.0.0版的试用许可证密钥和2.0.2版的版式。
public ByteArrayInputStream pdfReport()
throws MalformedURLException, IOException, DocumentException, SurveyException {
LicenseKey.loadLicenseFile("E:/licence-key.xml");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfWriter pdfWriter = new PdfWriter(outputStream);
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document layoutDocument = new Document(pdfDocument, pagesize);
/***************Some Codes***************/
layoutDocument.close();
return new ByteArrayInputStream(outputStream.toByteArray());
}
以上方法在我的控制器类中调用。首先,如果我点击了请求,则生成了pdf文件,但是在第二个请求中,它显示了“ 406不可接受”。错误显示如下:
java.lang.NullPointerException: null
at com.itextpdf.licensekey.validators.LicenseKey7Validator.updateProductsOnLoad(LicenseKey7Validator.java:437) ~[itext-licensekey-3.0.0.jar:na]
at com.itextpdf.licensekey.validators.LicenseKey7Validator.LoadLicense(LicenseKey7Validator.java:121) ~[itext-licensekey-3.0.0.jar:na]
at com.itextpdf.licensekey.LicenseKey.loadLicenseFileInternal(LicenseKey.java:182) ~[itext-licensekey-3.0.0.jar:na]
at com.itextpdf.licensekey.LicenseKey.loadLicenseFile(LicenseKey.java:69) ~[itext-licensekey-3.0.0.jar:na]
at com.itextpdf.licensekey.LicenseKey.loadLicenseFile(LicenseKey.java:94) ~[itext-licensekey-3.0.0.jar:na]
at com.survey.application.pdfGenerator.PdfReportGenerator.pdfReport(PdfReportGenerator.java:61) ~[classes/:na]
at com.survey.application.controller.PdfController.generateReport(PdfController.java:31) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]
我很困惑,它在生成第一个请求时是怎么回事,但在第二,第三等等中,它会引发异常。是加载许可证密钥文件的方法吗?任何建议将不胜感激。预先感谢。