java JRpdfExporter 不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7606023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 20:40:13  来源:igfitidea点击:

JRPdfExporter is not working

javajasper-reportsitext

提问by JN_newbie

I have createad a report in jasper report, when i have wrote the code in servlet to export the report in pdf it is not displaying the report.

我在 jasper 报告中创建了一份报告,当我在 servlet 中编写代码以导出 pdf 报告时,它没有显示报告。

JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
//OutputStream ouputStream = response.getOutputStream();
//pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "C:/reports/payment.pdf");
pdfExporter.exportReport();

Now during debugging when debugger came to at this line JRPdfExporter pdfExporter = new JRPdfExporter(); it simply goes in finally block rather in next line. I am stuck into this any solutions.

现在在调试过程中,当调试器来到这一行 JRpdfExporter pdfExporter = new JRpdfExporter(); 它只是进入 finally 块而不是下一行。我被困在这个任何解决方案中。

and the Exception is:

异常是:

java.lang.NoClassDefFoundError: com/lowagie/text/DocumentException
java.lang.ClassNotFoundException: com.lowagie.text.DocumentException

采纳答案by Rangi Lin

Your code looks fine, and It compiles and runs correctly. I suspect that problem is inside JasperPrint. Make sure you actually complie a JasperPrintfrom your JRXML file.

您的代码看起来不错,并且可以正确编译和运行。我怀疑问题出在里面 JasperPrint。确保您确实JasperPrint从 JRXML 文件中编译了 a 。

If you set an empty JasperPrintinto the JRPdfExporter, it will still runs correctly, but will result an empty PDF file.

如果设置为空JasperPrint进入JRPdfExporter,它仍然可以正常运行,但会导致一个空的PDF文件。

Hope this help you locate the error.

希望这可以帮助您定位错误。

EDIT :

编辑 :

these Exception messages you provided are indicated that JVM can not locate DocumentException, according to package name, that's a class from iText library, if you have used iText, make sure you have included iText in your classpath.

您提供的这些异常消息表明 JVM 无法DocumentException根据包名找到iText 库中的类,如果您使用过 iText,请确保您已在类路径中包含 iText。

回答by mahesh

I think you are not included "iText-2.1.7.js2.jar" file to your classpath. First include mentioned file then it will work fine.

我认为您的类路径中没有包含“iText-2.1.7.js2.jar”文件。首先包含提到的文件然后它会正常工作。

Hope it will help to you.

希望对你有帮助。

回答by Anthony Pi?ero

Using maven just put your jasper dependency:

使用 maven 只需放置您的 jasper 依赖项:

    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>3.7.6</version>
    </dependency>

and he put the dependency

他把依赖

enter image description here

在此处输入图片说明

回答by DON

Just include itext-1.2.jarinside your class path.

只需包含itext-1.2.jar在您的类路径中。

回答by Juan Rada

You have to add http://itextpdf.com/jar file

你必须添加http://itextpdf.com/jar 文件