Java – when there is more data, the Jasper report exports empty data in PDF format
•
Java
I have a report exported in Excel, PDF and word using Jasper report I use the XML file as the data source of the report, but when the data increases, the Jasper report only exports the empty file in PDF format. When I reduce the data content, it will export the data correctly Is there a limit on PDF size?, How do we manage the size in Jasper reports from Java?
My JRXML is really big, so I can't add it here. I added the Java code I used to export the content:
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);
Solution
Try to set the content length:
response.setContentLength(outputStream_.toByteArray().length)
See if this can solve your problem
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码