How to Create Cover in a Report Using iReport

4

I'm using iReport 5.5.2 and I've tried in many ways to add a cover to the report, which is necessary, but to no avail. I've already tried adding the isTitleNewPage attribute in the Title band of iReport, but that did not work and I looked for some attribute to start a band on a new page and then the rest on another page and it does not work. I saw in a forum, that I can not remember the name, a user informing that he solved the problem by creating two separate PDF files and then joining the two with iText, but I believe this is POG.     

asked by anonymous 13.05.2014 / 19:02

1 answer

4

When I had to add any pages in reports or even put together several reports, the way was to join the documents with iText.

This is not POG! POG is to use a tool for a purpose other than the one it was designed for.

JasperReports (iReport is just the editor) was a project to generate reports from data sources and not documents containing text. IText is designed to create and manipulate PDF files. Therefore, nothing is fairer than to leave each tool with its function.

On the other hand, I did a brief survey to find out if the JasperReports staff could have implemented something specific about this and I came to a blog that shows a snippet of code that allows you to merge two reports together. I did not test the solution, but if it works you can create another report that is just the cover and merge with the report that contains the data.

See the code snippet:

JasperPrint jp1 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));
JasperPrint jp2 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));

List pages = jp2 .getPages();
for (int j = 0; j < pages.size(); j++) {
    JRPrintPage object = (JRPrintPage)pages.get(j);
    jp1.addPage(object);
}
JasperViewer.viewReport(jp1, false);

Obviously it would be necessary to adapt the example and verify that its API version is compatible with this method.

    
14.05.2014 / 17:45