Jump to content
We've recently updated our Privacy Statement, available here ×

[SOLVED] Adding n Subreports using java code


accounts_8

Recommended Posts

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

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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();[/code]

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...