Generate report IReport / Jasper Report containing 2 pages (with 3 columns each) on the same sheet in landscape mode

6

I'm making a report for a client and I can not mount it according to their need. What it needs is to generate a PDF of A4 sheet in landscape mode, each sheet containing two pages (odd and even), and each page with 3 columns.

I have already researched several forums (both here in the GUJ and others) but in none I was able to find something to help me with this resolution, and I'm already late with the delivery of this software, where only this product report is missing. p>

For example, I am sending the image of the result that I need in this post.

Please, does anyone know and / or ever had to generate a two-page report on the same page? The 3 columns I can generate, but only on 1 page.

If you have any idea, or even suggestion of another way to generate, you will be very welcome, because my possibilities are very close to exhausted, so I need and much help from you.

I'm using IReport version 5.6.0

Thank you!

    
asked by anonymous 30.11.2014 / 04:18

2 answers

0

I found this thread discussing more or less the same problem as yours. The curious thing is that Jasper's Staff response was in line with my comment on your question. =]

I will copy the code that was posted there with a few comments from me. I have not tested here, but it seems to make sense in the universe I know of from JasperReports:

//Começa configurando o relatório normalmente!
JasperDesign jd = JRXmlLoader.load(ResourceUtils.getFile(getFileResourcesJRXML("myjasper_A5.jrxml")));
JasperReport jrRH02 = JasperCompileManager.compileReport(jd);
jp = JasperFillManager.fillReport(jrRH02, data, dataSource);

getResponse().setContentType("application/pdf");
ServletOutputStream outputStream = getResponse().getOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, baos);
exporter.exportReport();

//Não entendi porquê ele fez isso...    
exporter.reset();
exporter = null;
System.gc();

//Aqui é onde a hackeada começa:
Document document = new Document();
//Define as dimensões da página no braço
document.setPageSize(new Rectangle(jp.getPageWidth(), jp.getPageHeight() * 2)); // This is because A4 Size == 2 * A5
//lê os dados do relatório originalmente produzido (páginas separadas)
PdfReader pdfReader = new PdfReader(baos.toByteArray());
//cria um novo escritor de PDF usando a configuração acima
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
document.open();
PdfContentByte cb = writer.getDirectContent();
//Faz um loop que lê as páginas do relatório inicial
// e coloca no relatório novo
//Estranhamente ele deixou a definição do loop incompleto,
// não deve ser difícil completar...
for(int i = 1; i ...){
    document.newPage();
    PdfImportedPage page = writer.getImportedPage(pdfReader, i);
    cb.addTemplate(page, 0, 0);
    cb.addTemplate(page, 0, jp.getPageHeight()); 
}
outputStream.flush();
document.close();
    
08.04.2015 / 03:26
0

In this case I would do the following: In the A4 landscape I would put 2 SubReports with 400 pixels each duly configured the leftovers of the size, and in the middle vi that has a vertical line, well, add a vertical line. Configuring the SubReports both in Ireport/JasperStudio and in code, dividing my views into two lists (one for each SubReport ) for no redundancy.

    
21.10.2015 / 14:32