Pageheader cutted on new page

0

Sometimes the pageheader is cut out when is in the begining of a page. Seems like a bug, because i'm not capable to reproduce this problem, some pages works fine but sometimes no(like the example, its missing pageheader "17 - blablablabla" ).
All .jrxml are the same with no diference, in jasper studio is all ok.
I'm using DynamicJasper to generate my many tables like that example in the .png  and joining for export in pdf. I will show a bite of code thats run this.
Somebody can help me pls?

private void generateSection(String titleSection, DynamicReportBuilder drb, Map<String, Object> section, Map<String, Object> params, boolean startOnNewPage) {
      // Section
      Style sectionStyle = new StyleBuilder(false, "sectionStyle")
            .setTransparent(false)
            .setBackgroundColor(new Color(155, 205, 155))
            .setVerticalAlign(VerticalAlign.MIDDLE)
            .setHorizontalAlign(HorizontalAlign.CENTER)
            .setFont(FontPri.DEJAVU_SANS_LARGE_BOLD)
            .build();
      DynamicReportBuilder drbSection = new DynamicReportBuilder()
            .setTitle(titleSection).setTitleStyle(sectionStyle)
            .setTitleAnchorNameExpression("\"" + titleSection + "\"")
            .setTitleBookmarkLevel(1)
            .setMargins(0, 0, 30, 15)
            .setWhenNoDataAllSectionNoDetail();
      DynamicReport drSection = drbSection.build();
      drb.addConcatenatedReport(drSection,
            new ClassicLayoutManager(),
            null,
            DJConstants.DATA_SOURCE_ORIGIN_PARAMETER,
            DJConstants.DATA_SOURCE_TYPE_JRDATASOURCE,
            startOnNewPage);
      section.forEach((k, o) -> {
         if (o instanceof Map) {
            boolean isInformacoesGerais = "informacoesGerais.dados".equals(k);
            Map<String, Object> tab = cast(o, Map.class);
            DynamicReportBuilder drbTab = new DynamicReportBuilder()
                  .setReportName(k)
                  .setPrintBackgroundOnOddRows(true)
                  .setMargins(30, 15, 30, 15)
                  .setTitleHeight(15).setHeaderHeight(15)
                  .setUseFullPageWidth(true)
                  .setWhenNoDataAllSectionNoDetail();
            setStyles(drbTab);
            // Titulo e fonte da tabela da tabela
            if (!isInformacoesGerais) {
               drbTab.setTitle(tab.get("cod").toString() + " - " + tab.get("_descricao").toString());
               drbTab.addAutoText("Fonte: " + coalesce(tab.get("_fonte"), "Desconhecida"),
                     AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT, 555,
                     new Style("fonteStyle"));
            }
            // Configuração colunas da tabela
            List<Map<String, Object>> fields = cast(tab.get("_fields"), List.class);
 
            // Adicionar colunas
            Boolean isMulti = (Boolean) tab.get("_isMulti");
            Boolean isDescricao = !tab.values().stream()
                  .filter(row -> row instanceof Map)
                  .allMatch(row -> cast(row, Map.class).get("_descricao") == "");
            if (!isMulti) {
               if (isDescricao) {
                  drbTab.addColumn(ColumnBuilder.getNew()
                        .setColumnProperty("_descricao", String.class.getName())
                        .setTitle(isInformacoesGerais ? null : tab.get("_eDesc").toString()).setWidth(150)
                        .setHeaderStyle(new Style("descricaoHeaderStyle"))
                        .setStyle(new Style("descricaoStyle"))
                        .build());
               }
               for (Map<String, Object> field : fields) {
                  drbTab.addColumn(ColumnBuilder.getNew()
                        .setColumnProperty(field.get("key").toString(), String.class.getName())
                        // sub.get("tipo") -> String, Integer, Float...
                        .setTitle(isInformacoesGerais ? null : field.get("descricao").toString()).setWidth(80)
                        .build());
               }
               // Transformar dados e inserir em parametros
               ArrayList<Map<String, ?>> list = new ArrayList<>();
               List<Integer> order = (List<Integer>) tab.get("_order");
               for (Integer ecod: order) {
                  Map<String, Object> evalue = cast(tab.get(ecod.toString()), Map.class);
                  if (evalue == null) continue;
                  HashMap<String, Object> row = new HashMap<>();
                  row.put("_descricao", evalue.getOrDefault("_descricao", "--").toString());
                  fields.forEach(field -> {
                     Object resposta = evalue.get(field.get("key"));
                     if(empty(resposta)) resposta = "";
                     Object tipo = field.get("tipo"); // É por tipo mas por enquanto é possivel mapear pelo tipo da instancia
                     if (resposta instanceof Map) {
                        resposta = ((Map) resposta).getOrDefault("descricao", "");
                     } else if (resposta instanceof List) {
                        resposta = ((List) resposta).stream().map(r -> ((Map) r).getOrDefault("descricao", "")).reduce((d0, d1) -> d0 + "\n" + d1).orElse("");
                     }
                     row.put(field.get("key").toString(), resposta.toString());
                  });
                  list.add(row);
               }
               params.put(k, new JRMapCollectionDataSource(list));
            } else {
               int indexColField = 0;
               if (isDescricao) {
                  int width = 150;
                  String eDesc = tab.get("_eDesc").toString();
                  // Estilizar condicional
                  int qtdFields = (Integer) ((ArrayList) tab.get("_fields")).stream().filter(f -> f instanceof Map)
                        .map(o1 -> ((List)((Map)o1).getOrDefault("fields", list(0))).size())
                        .reduce((o1, o2) -> (int)o1 + (int)o2).get();
                  if (qtdFields > 18) width = 150;
                  else if (qtdFields > 14 && eDesc.length() > 3) width = 150;
                  else if (qtdFields > 9) width = 70;
                  else if (qtdFields > 6) width = 100;
                  // ---------------
                  drbTab.addColumn(ColumnBuilder.getNew()
                        .setColumnProperty("_descricao", String.class.getName())
                        .setTitle(eDesc).setWidth(width)
                        .setHeaderStyle(new StyleBuilder(true, "descricaoMHeaderStyle", "headerStyle")
                              .setVerticalAlign(VerticalAlign.MIDDLE)
                              .setStretching(Stretching.RELATIVE_TO_BAND_HEIGHT)
                              .build())
                        .setStyle(new Style("descricaoStyle"))
                        .build());
                  indexColField = 1;
               }
               for (Map<String, Object> field : fields) {
                  Boolean isMultiField = "multi".equals(field.get("tipo"));
                  if(isMultiField) {
                     List<Map<String, Object>> subfields = (List<Map<String, Object>>) field.get("fields");
                     subfields.forEach(subfield -> {
                        String keyProperty = field.get("key") + "." + subfield.get("key");
                        drbTab.addColumn(ColumnBuilder.getNew()
                              .setColumnProperty(keyProperty, String.class.getName())
                              .setTitle(subfield.get("descricao").toString()).setWidth(85)
                              .build());
                     });
                     drbTab.setColspan(indexColField, subfields.size(), field.get("descricao").toString());
                     indexColField += subfields.size();
                  } else {
                     drbTab.addColumn(ColumnBuilder.getNew()
                           .setColumnProperty(field.get("key").toString(), String.class.getName())
                           .setTitle(field.get("descricao").toString()).setWidth(80)
                           .setHeaderStyle(new StyleBuilder(true, "descricaoMHeaderStyle", "headerStyle")
                                 .setHorizontalAlign(HorizontalAlign.CENTER)
                                 .setVerticalAlign(VerticalAlign.MIDDLE)
                                 .setStretching(Stretching.RELATIVE_TO_BAND_HEIGHT)
                                 .build())
                           .build());
                     indexColField += 1;
                  }
               }
               // Transformar dados e inserir em parametros
               ArrayList<Map<String, ?>> list = new ArrayList<>();
               List<Integer> order = (List<Integer>) tab.get("_order");
               for (Integer ecod: order) {
                  Map<String, Object> evalue = cast(tab.get(ecod.toString()), Map.class);
                  if (evalue == null) continue;
                  HashMap<String, Object> row = new HashMap<>();
                  row.put("_descricao", evalue.get("_descricao").toString());
                  fields.forEach(field -> {
                     Boolean isMultiField = "multi".equals(field.get("tipo"));
                     if(isMultiField) {
                        List<Map<String, Object>> subfields = (List<Map<String, Object>>) field.get("fields");
                        subfields.forEach(subfield -> {
                           String keyProperty = field.get("key") + "." + subfield.get("key");
                           Object resposta = evalue.get(keyProperty);
                           if (empty(resposta)) resposta = "";
                           Object tipo = field.get("tipo"); // É por tipo mas por enquanto é possivel mapear pelo tipo da instancia
                           if (resposta instanceof Map) {
                              resposta = ((Map) resposta).getOrDefault("descricao", "");
                           } else if (resposta instanceof List) {
                              resposta = ((List) resposta).stream().map(r -> ((Map) r).getOrDefault("descricao", "")).reduce((d0, d1) -> d0 + "\n" + d1).orElse("");
                           }
                           row.put(keyProperty, resposta.toString());
                        });
                     } else {
                        Object resposta = evalue.getOrDefault(field.get("key"), "");
                        Object tipo = field.get("tipo"); // É por tipo mas por enquanto é possivel mapear pelo tipo da instancia
                        if (resposta instanceof Map) {
                           resposta = ((Map) resposta).getOrDefault("descricao", "");
                        } else if (resposta instanceof List) {
                           resposta = ((List) resposta).stream().map(r -> ((Map) r).getOrDefault("descricao", "")).reduce((d0, d1) -> d0 + "\n" + d1).orElse("");
                        }
                        row.put(field.get("key").toString(), resposta.toString());
                     }
                  });
                  list.add(row);
               }
               params.put(k, new JRMapCollectionDataSource(list));
            }
            try {
               DynamicReport drTab = drbTab.build();
               JasperReport jrTab = DynamicJasperHelper.generateJasperReport(drTab, new ClassicLayoutManager(), null);
               jrTab.getPageHeader().setSplitType(SplitTypeEnum.PREVENT);
               if(Env.isDev()) DynamicJasperHelper.generateJRXML(jrTab, "UTF-8",System.getProperty("user.dir")+ "/target/reports/" + k + ".jrxml");
               drb.addConcatenatedReport(jrTab, k,
                     DJConstants.DATA_SOURCE_ORIGIN_PARAMETER,
                     DJConstants.DATA_SOURCE_TYPE_JRDATASOURCE);
            } catch (Exception e) {
               logger.error(e);
            }
         }
      });
   }

Attachments: 
thiago.pimenta_1's picture
Joined: Jun 7 2021 - 6:33am
Last seen: 1 week 2 days ago

The example of cut is in the attachments

thiago.pimenta_1 - 1 week 3 days ago

You should try column header.

harshalsonar777 - 1 week 2 days ago

1 Answer:

0

You should try column header.

harshalsonar777's picture
Joined: Jun 16 2020 - 4:00am
Last seen: 1 week 1 day ago
Feedback