Question

I have different modules in my application. Each module can be exported in excel, word and pdf. The format of report are in either landscape or portrait. Now I need to compile all those reports and export as a single. But I am facing a problem that while exporting, DynamicJasper shows in a single format only i.e either landscape or portrait.

How can I show my report using both format in a single report using DynamicJasper API?

Was it helpful?

Solution

You can create a Master Report and add subreports to it, this is an example of the master report and how to add Subreports:

public DynamicReport buildDynamicReport() throws ReportDocumentGenerationException {
  DynamicReportBuilder drb = new DynamicReportBuilder();
  drb.setDetailHeight(detailHeight)     
  .setMargins(properties.getReportMargins().getTopMargin(), properties.getReportMargins().getBottomMargin(), properties.getReportMargins().getLeftMargin(), properties.getReportMargins().getRightMargin())     
  .setDefaultStyles(null, null, null, getSpoolStyle(SpoolRow.PLAIN_ATTRIBUTE))    
  .setPageSizeAndOrientation(new Page(**/*Your document dimensions and orientation*/**)
  .setColumnsPerPage(1);
   for(ReportDocumentInformationPage page: reportInformation.getPaginas()){
            drb.addConcatenatedReport(getPageSubReport(page.getPageNumber()),new ClassicLayoutManager(),"DS"+page.getPageNumber().toString(),DJConstants.DATA_SOURCE_ORIGIN_PARAMETER, DJConstants.DATA_SOURCE_TYPE_JRDATASOURCE,!page.getPageNumber().equals(1));
            params.put("DS"+page.getPageNumber().toString(), getReportJRDataSource(page.getPageNumber())  );
        }
        drb.setUseFullPageWidth(true);
        DynamicReport dr = drb.build();
        return dr;
    }

This is an example on how to create those subreports:

*private DynamicReport getPageSubReport(int i) throws ReportDocumentGenerationException {
        try{
            DynamicReportBuilder drb = new DynamicReportBuilder();
            drb.setDetailHeight(detailHeight)
            .setReportName("Reporte"+i)
            .setMargins(properties.getReportMargins().getTopMargin(), properties.getReportMargins().getBottomMargin(), properties.getReportMargins().getLeftMargin(), properties.getReportMargins().getRightMargin())
            .setDefaultStyles(null, null, null, getSpoolStyle(SpoolRow.PLAIN_ATTRIBUTE))    
            .setPageSizeAndOrientation(new Page(**/*Your specific Page dimensions and orientation***/)
            .setColumnsPerPage(1);

            AbstractColumn spoolColumn = ColumnBuilder.getNew()     
            .setColumnProperty("value", String.class.getName())     
            .setTitle(null)     
            .setWidth(150)
            .build();       
            spoolColumn.setConditionalStyles(getSpoolConditionalStyle());

            drb.addColumn(spoolColumn);
            drb.setUseFullPageWidth(true);
            drb.addField("attributes", String.class.getName());
            DynamicReport dr = drb.build();
            return dr;
        }catch(ColumnBuilderException cbe){
            cbe.printStackTrace();
            throw new ReportDocumentGenerationException("No se pudo definir correctamente la columna del reporte para la pagina "+i);
        }catch(Exception e){
            e.printStackTrace();
            throw new ReportDocumentGenerationException("No se pudo generar la pagina "+i+" del reporte");
        }
    }*

Hope it helps.

OTHER TIPS

If you have or can get a handle your JasperPrint object, then you can set the orientation:

final JasperDesign jasperDesign = JRXmlLoader.load(someInputStream);
final JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
final JasperPrint jasperPrint =   jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, dataSourceOrConnection);    
...
jasperPrint.setOrientation(OrientationEnum.LANDSCAPE); // Pick
jasperPrint.setOrientation(OrientationEnum.PORTRAIT);  // One 
...
someJRExporter.exportReport();

You can also set the page width and height with the JasperPrint object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top