2011-12-08 10 views
6

El objeto jasperPrint tiene orientación vertical, pero el objeto jasperPrint2 tiene orientación horizontal. Quiero combinar las dos jasperprints para producir UN archivo pdf pero manteniendo su orientación original. Cuando agrego las páginas de jasperPrint2 a jasperPrint, el jaspePrint final tiene orientación vertical ... Probé el jasperPrint.setOrientation(JasperReport.ORIENTATION_LANDSCAPE) pero no cambió nada.Cómo combinar varios objetos JasperPrint para tener un informe con orientación de página mixta

¿Cómo puedo producir UN archivo pdf de las dos jasperprints manteniendo su orientación original?

Tengo el siguiente código:

JasperReport report = (JasperReport) JRLoader.loadObject(reportFile2.getPath()); 
jasperPrint = JasperFillManager.fillReport(report, parameters, conn); 

JasperReport report2 = (JasperReport) JRLoader.loadObject(reportFile.getPath()); 
jasperPrint2 = JasperFillManager.fillReport(report2, parameters, conn); 

List pages = jasperPrint2.getPages(); 
for (int j = 0; j < pages.size(); j++) { 
    JRPrintPage object = (JRPrintPage) pages.get(j); 
    jasperPrint.addPage(object); 
} 
+1

Usted puede mirar en [este mensaje] (http://stackoverflow.com/questions/8564163/how-to-collate-multiple-jrxml-jasper-reports-into-a-one-single-pdf -archivo de salida) –

Respuesta

1

Usted puede lograr esto haciendo un lote de exportación.

//put all the jasperPrints you want to be combined into a pdf in this list 
List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>(); 

JasperReport report = (JasperReport) JRLoader.loadObject(reportFile2.getPath()); 
jasperPrintList.add(JasperFillManager.fillReport(report, parameters, conn)); 

JasperReport report2 = (JasperReport) JRLoader.loadObject(reportFile.getPath()); 
jasperPrintList.add(JasperFillManager.fillReport(report2, parameters, conn)); 

ByteArrayOutputStream baos = new ByteArrayOutputStream();  
JRPdfExporter exporter = new JRPdfExporter();  
//this sets the list of jasperPrint objects to be exported and merged 
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList); 
//the bookmarks is a neat extra that creates a bookmark for each jasper print 
exporter.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE); 
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);  
exporter.exportReport();   
return baos.toByteArray(); 
Cuestiones relacionadas