[SOLVED] Adding n Subreports using java code

0

Hey JR Community,

any hint how to solve my following problem would be great:

Setup:

I have standalone Java Application (openJDK 11.0.2) with JR 6.8.0. I wand to create a PDF with a basic structure:

  • titlepage,
  • toc,
  • ...,
  • <dynamic content>,
  • ...

The dynamic content contains 1 to many pages which are designed equally (same report, different parameters).

Question:

How can Ì achieve to create such a PDF usind predesigned reports (e.g. basic-report.jasper and dynamic-content.jasper) and java code only? Especially adding x pages where every page depends on the same report.

 

Any help/hint would be great!

 

Best regards from Hamburg,

Christoph

 

accounts_8's picture
Joined: May 18 2019 - 11:44pm
Last seen: 3 weeks 3 days ago

2 Answers:

0

Hi, will the Title and also the TOC also be part of a JasperReport or is this some content you will generate manually with iText or whatever?

I'm not familiar with the (newer) Book logic as I was stuck several years to an older version of iReport/JapserReports (5.5.1) at my old company - but I've read something about generating TOCs etc with the later versions of JasperReports (6.x) . Perhaps you could start "googling" for that also.

Otherwise you could generate several so called JrPrint Objects (filled JasperReports) and combine them into one PDF File using the JRExporter Util (no matter if it's X-times the same report or perhaps also different reports) :

something like this:

JRExporter exporter = new JRPdfExporter(); 
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, yourPreFilledJasperPrintList); 
exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, yourTargetPDFStream); 
exporter.exportReport();

Another solution could also be, to combine several reports into one "big" report using SubReports... so that ALL your static content and dynamic content is just one call to the FillManager and just one simple export call to the JRPdfExporter. You could also create at runtime via API an JRDesign and put several SubReports together using just the Jasper-API ... so many leads to Rome :-)

just give it a try.

hth + regards the river Elbe down from Dresden ;-)

C-Box

C-Box's picture
1435
Joined: Jul 19 2006 - 5:58pm
Last seen: 3 min 57 sec ago
0

Hey All, hey C-Box,

finally I managed to solve my problem (at least partially). What I did was:

Preparation:

  1. Created a Report-Book, saved as JRXML within my resources
  2. Created a bunch of SubReports, saved as JASPER within my resources
  3. NOTE: SubReports were not embedded inside my Report-Book

During Runtime:

  1. Load Report-Book as JasperDesign
  2. In preferred Order and for each SubReport:
  3. Add JRDesignPart with SubReportPart to DetailsSection of ReportBook
  4. Load SubReport.JASPER as JasperReport
  5. Add SubReport to Parameters
  6. Add Custom Parameter Map as Parameter for Subreport

Regards,

Christoph

 

accounts_8's picture
Joined: May 18 2019 - 11:44pm
Last seen: 3 weeks 3 days ago
Feedback