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

Asked

Viewed 2,804 times

7

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

I’ve researched several forums (both here in GUJ and others) but in none I could find something to help me with this resolution, and I’m already late with the delivery of this software, where only missing this product report.

To illustrate better, I am sending this post the image of the result I need.

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

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

I am using Ireport version 5.6.0

Thank you!

inserir a descrição da imagem aqui

  • To illustrate better, I am sending this post the image of the result I need. - Where is the image?

  • I had sent but the image did not go up. Now yes it follows her in the post.

  • What is the difference between your problem and a report with a 6-column page? Another possibility (somewhat capenga =/ ) would just be to guide your client to use the printer software to print two pages per sheet...

  • Was any answer helpful to you? Could you choose one and mark it as accepted?

  • I think the concept of Jasper Raport is being mixed. Are you saying you want the Detail repeating 2x in the sheet body per page ? If so, I believe that the solution proposed by @Nigini is the most appropriate

2 answers

1

I found that thread discussing more or less the same problem as yours. The curious thing is that the answer from Jasper’s staff was in line with my comment on your question. =]

I’ll copy the code that was posted there with a few comments from me. I haven’t tested it here, but it seems to make sense in the universe I know of 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();

1

In this case I would do the following: In the landscape A4 would put 2 SubReports with 400 pixels each properly configured the leftovers of the size, and in the middle vi that has a vertical line, well, add a vertical line. Configure the SubReports so much on the Ireport/JasperStudio and in code, dividing my exhibits into two lists(One for each SubReport) for there to be no redundancy.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.