o esquema ´e o seginte:
- cria-se dois relatorios iguais no conteudo, um com a margem certa e outro com a margem recuada
- depois passa pegando uma folha de cada para gerar o relatorio final
Report report = new Report(txDateInitial.getText(), txDateFinal.getText());
report.setBeginBefore(beginBefore);
report.setIsVerso((rbFrente.isSelected() ? Boolean.FALSE: Boolean.TRUE));
report.setFolha(folha);
String pathReportRecto = Util.getResource().getProperty("pathReportRecto");
JasperPrint printRecto = report.getReport(pathReportRecto);
String pathReportVerso = Util.getResource().getProperty("pathReportVerso");
report.setFolha((rbFrente.isSelected() ? folha-1: folha));
JasperPrint printVerso = report.getReport(pathReportVerso);
JasperPrint jasperPrint = new JasperPrint();
jasperPrint.setOrientation(JasperReport.ORIENTATION_LANDSCAPE);
jasperPrint.setName("Protocolo");
if (rbFrente.isSelected()) {
jasperPrint.setPageWidth(printRecto.getPageWidth());
jasperPrint.setPageHeight(printRecto.getPageHeight());
} else {
jasperPrint.setPageWidth(printVerso.getPageWidth());
jasperPrint.setPageHeight(printVerso.getPageHeight());
}
int i = 0;
Iterator<jrprintpage> iterator = printRecto.getPages().iterator();
Iterator<jrprintpage> iterator2 = printVerso.getPages().iterator();
if (rbFrente.isSelected()) {
while ( iterator.hasNext() ){
if (i % 2 == 0) {
jasperPrint.addPage(i, iterator.next());
if (iterator2.hasNext())
iterator2.next();
} else {
jasperPrint.addPage(i, iterator2.next());
if (iterator.hasNext())
iterator.next();
}
i++;
}
} else {
while ( iterator2.hasNext() ){
if (i % 2 == 0) {
jasperPrint.addPage(i, iterator2.next());
if (iterator.hasNext())
iterator.next();
} else {
jasperPrint.addPage(i, iterator.next());
if (iterator2.hasNext())
iterator2.next();
}
i++;
}
}
report.closeConnection();
if (jasperPrint.getPages().size()>0) {
Preview preview = new Preview(jasperPrint);
preview.setVisible(true);
preview.setExtendedState(MAXIMIZED_BOTH);
} else {
JOptionPane.showMessageDialog( this, "Os parametros informados não geraram nenhum relatório.", "Erro", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
ex.printStackTrace();
}
Nenhum comentário:
Postar um comentário