如何在JasperReport中将打印顺序设置为"水平"时自动拉伸细节带?

Mat*_*ari 7 java jasper-reports

我有一份水平打印的主报告.它有5列.在每列我想要一个子报告.所以我创造了这个:

主要报告

子报告就是这样的:

子报表

问题是,当我运行时,我得到以下异常:

net.sf.jasperreports.engine.JRRuntimeException: Subreport overflowed on a band that does not support overflow.
Run Code Online (Sandbox Code Playgroud)

看起来像jasper报告在其中有子报告并且打印顺序设置为水平时不能垂直拉伸细节带.

我该怎么做才能避免这个错误,实现我想要的?

Mat*_*ari 1

我找到了这个问题的解决方案。经过深入搜索后,遗憾的是,我发现在 Jasper Reports 上无法执行此操作,因为无论如何,当您水平打印报告时,“详细信息”带永远不会改变其高度。因此,溢出的子报表或文本字段将引发异常。

\n\n

此问题的解决方法是在没有报告的情况下工作,例如使用 iText 等 PDF 生成器。\n这是我为实现我想要的 iText(如果有人需要)而编写的代码:

\n\n
Document document = new Document();\nFile arquivo = new File("C:\\\\Users\\\\Mateus\\\\Desktop\\\\testez\xc3\xa3ozar\xc3\xa3oz\xc3\xa3o.pdf");\nPdfWriter.getInstance(document, new FileOutputStream(arquivo));\ndocument.open();\n\nLinkedHashMap<Produto, LinkedHashMap<String, List<PrePedidoItem>>> produtos = createStructuredHashMap();\n\nfor (Produto produto : produtos.keySet()) {\n    PdfPTable table = new PdfPTable(5);\n    PdfPCell cellProduto = new PdfPCell();\n    Phrase phraseProduto = new Phrase(String.valueOf(produto));\n    phraseProduto.setFont(new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD|Font.UNDERLINE, new BaseColor(50, 65, 200)));\n    cellProduto.addElement(phraseProduto);\n    cellProduto.setColspan(5);\n    cellProduto.setHorizontalAlignment(PdfPCell.ALIGN_MIDDLE);\n    cellProduto.setBorder(Rectangle.NO_BORDER);\n    cellProduto.setPaddingBottom(10);\n    cellProduto.setPaddingTop(20);\n    table.addCell(cellProduto);\n    LinkedHashMap<String, List<PrePedidoItem>> mapas = produtos.get(produto);\n    int mapasAdicionados = 0;\n    for (String mapa : mapas.keySet()) {\n        PdfPCell cellMapa = new PdfPCell();\n        Phrase phraseMapa = new Phrase(mapa);\n        phraseMapa.setFont(new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD, new BaseColor(215, 100, 0)));\n        cellMapa.addElement(phraseMapa);\n        List<PrePedidoItem> itensDoMapa = mapas.get(mapa);\n        for (PrePedidoItem item : itensDoMapa) {\n            DecimalFormat df = new DecimalFormat("###,##0.00");\n            Phrase phraseItem = new Phrase(df.format(item.getLargura()) + " x " + df.format(item.getComprimento()));\n            phraseItem.setFont(new Font(Font.FontFamily.HELVETICA, 9, Font.NORMAL, BaseColor.BLACK));\n            cellMapa.addElement(phraseItem);\n        }\n        cellMapa.setBorder(Rectangle.NO_BORDER);\n        table.addCell(cellMapa);\n        mapasAdicionados ++;\n        if(mapasAdicionados == 5) {\n            mapasAdicionados = 0;\n        }\n    }\n    PdfPCell celulaPreenchimentoMapas = new PdfPCell();\n    celulaPreenchimentoMapas.setColspan(5 - mapasAdicionados);\n    celulaPreenchimentoMapas.setBorder(Rectangle.NO_BORDER);\n    table.addCell(celulaPreenchimentoMapas);\n    document.add(table);\n}\n\ndocument.close();\nDesktop.getDesktop().open(arquivo);\n
Run Code Online (Sandbox Code Playgroud)\n