How can I use JasperFillManager.fillReportToStream?

 

I have a simple Java program that takes a .jrxml file, compiles it, then fills it. The data for the report is supplied in an XML file. After the fill is done, the data is exported to PDF.

<code style="margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">// Parse input document
Document document = JRXmlUtils.parse(new File(xmlFile));
 
// Set it as the data source in the parameters
parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
 
// Create and set the virtualizer
JRFileVirtualizer virtualizer = new JRFileVirtualizer(2, "/tmp");
virtualizer.setReadOnly(true);
parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
 
// Fill the report
String jasperFile = designFile.replaceAll(".jrxml",".jasper");
print = JasperFillManager.fillReport(jasperFile, parameters);
 
// Export the report to PDF
ArrayList<JasperPrint> jasperPrints = new ArrayList<JasperPrint>();
jasperPrints.add(print);
JRPdfExporter exp = new JRPdfExporter();
exp.setParameter (JRExporterParameter.JASPER_PRINT_LIST, jasperPrints);
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outFileName );
exp.exportReport();

My confusion is about the export

That fill line above works great for small reports, but once I get an XML source file approaching 1/2 MB, it will spin for over a day, regardless of setting the file virtualizer (which I do).

I see there is another method called

fillReportToSteam. My confusion is that with <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">fillReport, I have to do an extra step to export to PDF. What sort of stream is <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">fillReportToStream writing to, and how do I specify that? Will <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; ">fillReportToStream write to a PDF file?</p>
<p style="margin-top: 0px; border: 0px; font-size: 14px; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; text-align: left; ">I haven't been able to find any examples. I was hoping I could take advantage of the stream so that I could measure the progress and get these PDFs to complete in a normal span of time.</p>
<p style="margin-top: 0px; border: 0px; font-size: 14px; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; text-align: left; ">UPDATE: fillReportToStream doesn't work for PDF files, at least in 4.7. That's extremely unfortunate. It "creates" a PDF file, but it's corrups and can't be read. And even then, it doesn't work any different than what I do above. In other words, for my 1/2 MB source file, it just sits and churns forever with the PDF file at 0 bytes.</p>
<p style="margin-top: 0px; border: 0px; font-size: 14px; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; text-align: left; ">UPDATE 2: Looks like it creates JasperPrint files.</p>
<p style="margin-top: 0px; border: 0px; font-size: 14px; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; text-align: left; ">UPDATE 3: I have the "streaming" solution working for an extremely small file. But for the "large" file (like 1/2 of a MB is large) it churns at 100% CPU for 2 hours, and the file that is supposed to be "streamed" to is still at zero bytes.</p>
<p style="margin-top: 0px; border: 0px; font-size: 14px; vertical-align: baseline; background-color: rgb(255, 255, 255); clear: both; word-wrap: break-word; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; text-align: left; ">The hits seem to keep coming with this JasperReports library. I've done some interesting stuff with it in the past, but ever since I "upgraded" from 3.5 to 4.7, I am dead in the water.</p>
klingela's picture
Joined: Apr 22 2008 - 2:53pm
Last seen: 10 years 4 months ago

2 Answers:

Hi,

Can we see your JRXML report template? I suspect it is about a layout inconsistency that coupled with the specifics of the data you are having in the larger file causes JR to enter an infinite loop trying to create new pages just because some content never seems to fit a new page.

In any case, this is not related to how you fill the reports, to files, streams or whatever.

Thanks,
Teodor

teodord's picture
44905
Joined: Jun 30 2006 - 9:00am
Last seen: 1 week 4 days ago
I would be happy to upload the JRXMLs (there is a subreport and a sub-subreport). Is there a way to upload them here?
klingela - 10 years 4 months ago
And I am certain you are right. I am certain that some of the data will be bigger than a single page. How do I tell the jrxml or the subreport to allow the split?
klingela - 10 years 4 months ago
It works. I had to change the detail pages to "Split Type = Immediate".
klingela - 10 years 4 months ago

klingela,

Until somone with a better answer shows up, try looking at some of these performance related pages to see if they help in troubleshooting.  You might want to file an Issue under the Tracker for the export to PDF not working. 

Other interesting pages:

https://forums.oracle.com/forums/thread.jspa?threadID=2055773  -  About alternatives to fillReportToStream

There are also other support options available to you as well.

Hope this helps ....

 

djohnson53's picture
162764
Joined: May 25 2012 - 11:10am
Last seen: 1 year 1 month ago
Feedback
randomness