JasperReport- best approach for multiple pages static reports - java

i need to create a static report of 3 pages and every page contains static text and fields retrieved with a database query.
My first approach, after reading similar questions, was to create 3 separated report files (page1.jrxml, page2.jrxml and page3.jrxml) and then merge the resulting reports into a single one.
It works fine but sometimes happens that a field contains a very long string and a single file report generetes 2 pages, leading to an horrible printing because the first page is full but
the second contains one or few lines.
Can you suggest me a better approach?
Thanks

We use jrxml templates and we have only one jrxml. You do not need to have multiple files just split the static text to many DETAILS (paragraphs) and if the first page will overlap with few lines it will be inmediatelly followed by next detail.
In our app we use jasper from java and we pass the params with JasperFillManager.
We create template:
compiledTemplate = JasperCompileManager.compileReport(...);
and then we fill the variables
jasperPrint = JasperFillManager.fillReport(compiledTemplate, map with params, dto implementing JRDataSource);
and then we export it to pdf:
ret = JasperExportManager.exportReportToPdf(jasperPrint);
and thats it.

I've needed to split a report over several sheets primarily for Excel-export. It seems to be working while previewing on JasperServer also:
add report property net.sf.jasperreports.export.xls.one.page.per.sheet set to true
add property net.sf.jasperreports.export.xls.break.after.row set to true the the textfield you need a page break after (there's a similar one to break before)
Also you may name your sheets. Please see here:
http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.xls.one.page.per.sheet

Related

Is it possible to add a footnote depending on the page contents when using itext?

I am using Itext 5.5 and right now, I have a custom implementation of PdfPageEventHelper that adds a footer to the page containing Page number information.
Recent changes in my application lead to the existence of necessary footnotes. The way I am creating the PDF (dynamically created from a list of Components) makes it effectively impossible to determine which page contains which items, as that is part of customizable Styling options.
However, I need to add explanations to the footnote markers.
The approach I have now is to simply notify the PdfPageEventHelper that, somewhere in the document, there is at least one element that needs the (currently only) footnote, and then I add the explanatory footnote to every Page.
This is something I want to avoid, as the future might bring more footnotes and explanations.
So the question is:
Can I parse the current page content directly and scan for the existence of marker text? Or is there another way to see if the current page needs the explanatory footnote?
My failed approaches so far (all in onEndPage(PdfWriter, Document)):
PdfContentByte cb = writer.getDirectContent();
PdfReader reader = new PdfReader(cb.toPdf(writer());
// this led to InvalidPdfException
----
ColumnText ct = new ColumnText(cb);
ct.getCompositeElements();
// returned null, I expected the current page contents
----
OutputStreamCounter oc = writer.getOs();
// did not expose any useful methods. also, cannot read from OutputStream
Googling the problem yielded dozens of results - how to add a page number or how to add a document-static, user-specific header. But nothing page-depending.
Oh, and this, which is not really helpful:
Adding a pdf footer conditionally on certain pages in a multi-page pdf document
which seems basically to be the exact same problem as mine.
Essentially you'll have to do it the other way around:
Simply add a generic tag to the chunk of a footnote marker. Then your page event listener is informed about this generic tag between the start of the page and the end of it. If you set a flag in onGenericTag, therefore, your onEndPage method merely has to check (and later reset) that flag and add the footnote accordingly.
You can even use the generic tag text to differentiate between different markers and only add the matching footnotes.
For an example use of generic tags, have a look at examples using the Chunk.setGenericTag(String) method, e.g. the sandbox example GenericFields.
(I originally referenced the iText site URL https://developers.itextpdf.com/examples/page-events-itext5/page-events-chunks but due to a restructuring of that site it leads nowhere specific anymore; but you can still find a copy of the original page using the wayback machine.)

Dynamic report using jrxml

I am using iReport version 5.6.
Right now we're analyzing the requirement for a new project where the requirement is as follows.
We have a report which is designed in jrxml with almost 20 fields where user has to scroll to the right to get all values and hence tedious for the user when result size is too large.
Suggested requirement is as to configure the jrxml in such a way that user can select the column name for which the report should be generated.
Related image
We have done study on this and found the only possible solution may be to create a jrxml for each possible combination which seems to be not efficient for our project.
Could you please suggest is there any possible way to handle this situation?
Instead of using a seperate .jrxml file for each "view" you could duplicate the bands and use printWhen expressions to determine which band to display. Not a lot better than having separate .jrxml files but at least all the logic will be in the same file.
Another idea is to use parameters like showColA,showColB etc. Use those parameters to determine the column headers and values of those columns (this could get a little messy though)

JAsper Report 3.0 issue :

I am using jasper Reoprt Ireport 3.0 for Generating excel. my problem is I have One text field in that i want to keep below data which is coming from my database.
**Disclaimer: Please note that in case of disease conditions which can have both Acute and Chronic manifestations, they are considered as Chronic illness for analysis keeping in view the objective of the report.
Actually in jasper reoprt summary area i have given one text field but it is too small too keep this above line data. but still I want to keep whole data in small field in excel .
because normaly when we are typing in excel cell anything and when it become overflows then also it's looking like it has been typed in next cell but ,when we are clicking in another cell it will show in that cell only.whole data will come in that small cell without wrapping text filed.
just like it i want also through I-report 3.0 . I tried so much but I didn't find solution so i am posting here . please suggest if you faced same problem and got solution too. it will be helpful.
I don't want to merge it in multiple columns because if it will merge multiple columns then for calculating value through Excel column selection will be a problem. and V lookup we cant do so.
if the data in any cell is greater than 2 rows, then the remaining data just gets cut off and not displayed.
Maybe it is time to update. At this time JasperReports 6.x is the version to go, but ...
From my expierience JasperReports is the wrong tool to generate "clean" Excel documents. You get always layout informations in it that result in the behaviour you describe.
To get a clean Excel document I would suggest to go with Apache-Poi (https://poi.apache.org/) and generate it directly or simply to generate a CSV - file which can be easily opened using Excel.

Similar content on multiple pages -- Jasper report

My boss is killing me with the 'awesome' idea to generate Jasper report. As long as I am still alive, I have to ask experts here about how to make it happen.
The original requirement is to generate a pdf report with text and form(tables) in one page. I did it.
But the new requirement ask for a new report which contains four pages and each one contains the previous one page content, with only one change(insert different text on every page).
I did some research and didn't find a easy way to do it. So hope everyone on SO can give me a hint. Thanks a lot !
Could you hide and show columns based on expression? For example, map fields over fields in your template to account for all 4 pages, and for a given field only show data when PAGE_NUMBER = x or COLUMN_NUMBER = x.
In your query, you could create a constant to identify the page where each row of data should be printed and group on that constant.
Or -- 4 detail bands, and each is set to print only on the appropriate page.
If its the same text, then add the Text in String objects,
then you can use the same report, with different data-objects, which store the Strings for the text

Multi-page text report with BIRT

I have a report which I need to create with BIRT which is simply two large sections of text. The text will come in from XML, so I could use an XML datasource to load the text, but how do I just create a text section which could span multiple pages, I'm not using tabular data or anything like that.
If you have an XML source with two elements, each containing a large section of text, you can use the XML data source or the Scripted Data Source. Drop the Data Set into a table, and set the page break on the Detail row to 1 row and always. This will break up the two large text elements into separate pages.
No special measures should be required for a text section to split over multiple pages - this will happen automatically, if the field is large enough to require paging.
Something to note when having dynamic text span multiple pages:
The report layout should be set to "Auto Layout", otherwise it duplicates the text over multiple pages. This is only applicable when using the report viewer.
No good if you want to use fixed layout for a report.

Categories