java 当有更多数据时,Jasper 报告以 PDF 格式导出空数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1641884/
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
Jasper report exports empty data in PDF format when there is more data
提问by stanley
I have a report to be exported in excel, pdf and word using jasper reports. I use xml file as the DataSource for the report, but when the data increases jasper report exports empty file in only for PDF format, when i reduce the data content it export the data available correctly. is there any limitation to pdf size? , how can we manage the size in jasper reports from java?
我有一份报告要使用 jasper 报告以 excel、pdf 和 word 格式导出。我使用 xml 文件作为报告的数据源,但是当数据增加时,jasper 报告仅以 PDF 格式导出空文件,当我减少数据内容时,它会正确导出可用数据。pdf大小有限制吗?,我们如何管理来自 java 的 jasper 报告中的大小?
My jrxml is really big, so i cannot add it here, i have added my java code which i use to export the content:
我的 jrxml 真的很大,所以我不能在这里添加它,我添加了我用来导出内容的 java 代码:
JRAbstractExporter exporter = null;
if (format.equals("pdf")) {
exporter = new JRPdfExporter();
jasperPrint.setPageWidth(Integer.parseInt(pWidth));
} else if (format.equals("xls")) {
exporter = new JRXlsExporter();
} else if (format.equals("doc")) {
jasperPrint.setPageWidth(Integer.parseInt(pWidth));
}
exporter.setParameter(JRExporterParameter.JASPER_PRINT,
jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
outputStream_);
exporter.exportReport();
contents = outputStream_.toByteArray();
response.setContentType("application/" + format);
response.addHeader("Content-disposition",
"attachment;filename=" + name.toString() + "." + format);
采纳答案by RMorrisey
Try setting the content length:
尝试设置内容长度:
response.setContentLength(outputStream_.toByteArray().length)
See if this resolves your problem.
看看这是否能解决您的问题。
回答by false9striker
When there is no date source you can try this code
当没有日期源时,您可以尝试此代码
jasperReport = JasperCompileManager.compileReport(sourceFileName);
jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter,new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(jasperPrint, "D://.pdf")
Even if you do not have any data source and its a static data report giving JREmptyDataSource is important, otherwise you may get a blank report.
即使您没有任何数据源并且它的静态数据报告给 JREmptyDataSource 很重要,否则您可能会得到一个空白报告。
Check this link for more info https://stackoverflow.com/a/5334415/649451
检查此链接以获取更多信息https://stackoverflow.com/a/5334415/649451
-- Cheers!
——干杯!
回答by RMorrisey
maybe you don′t have data defined in report.
也许您没有在报告中定义数据。
try this code when generating report to avoid hiding sections when no data:
在生成报告时尝试使用此代码以避免在没有数据时隐藏部分:
JasperReport jasperReport = (JasperReport)JRLoader.loadObject ("report1.jasper");
**jasperReport.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);**
cheers!.
干杯!。
回答by Swapnil
I had similar issue. For large number of records pdf was getting blank report.
我有类似的问题。对于大量记录,pdf 得到空白报告。
This was solved by setting JRParameter.IS_IGNORE_PAGINATION to false.
这是通过将 JRParameter.IS_IGNORE_PAGINATION 设置为 false 来解决的。
回答by Pure Danger
A method that worked for me when dealing with big data and jasper reports is to first insert the data you need into a database table and then create a SQL statement on the jasper report that will join the table you created with the data you need. This puts more work on the database and less on the jasper library. Here is an example of a table that can be created to store report data.
在处理大数据和 jasper 报告时,一种对我有用的方法是首先将您需要的数据插入到数据库表中,然后在 jasper 报告上创建一条 SQL 语句,该语句将连接您创建的表和您需要的数据。这将更多的工作放在数据库上,而不是在 jasper 库上。下面是一个可以创建来存储报告数据的表的示例。
CREATE TABLE RE_EMPLOYEE(
EMPLOYEE_ID INT UNIQUE NOT NULL
COMPANY_ID INT UNIQUE NOT NULL
REPORT_NAME VARCHAR(20)
UNIQUE_USER_ID INT UNIQUE NOT NULL
PRIMARY KEY (EMPLOYEE_ID, COMPANY_ID)
);

