victor_38 Posted June 3, 2021 Share Posted June 3, 2021 I use jasper studio 6.17 and jasper library 6.17 and I have too much unused white space at the end of every page. I placed an image down to show the problem. So after record 21 there is a lot of free space that could easily fit records 22,23 and 24 but the space is not used, these records are displayed directly on page 2. This is the jrxml:<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.17.0.final using JasperReports Library version 6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="results" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isFloatColumnFooter="true"> <field name="text" class="java.lang.String"/> <field name="image" class="java.awt.Image"/> <detail> <band height="130" splitType="Stretch"> <textField isBlankWhenNull="true"> <reportElement x="0" y="0" width="595" height="29" isRemoveLineWhenBlank="true"/> <box padding="0"> <pen lineWidth="1.25" lineStyle="Solid" lineColor="#030303"/> </box> <textElement> <font fontName="DejaVu Sans" isBold="true"/> <paragraph lineSpacingSize="0.0"/> </textElement> <textFieldExpression><![CDATA[$F{text}]]></textFieldExpression> </textField> <image> <reportElement x="0" y="29" width="190" height="100" isRemoveLineWhenBlank="true"/> <box> <pen lineWidth="2.0" lineColor="#030303"/> </box> <imageExpression><![CDATA[$F{image}]]></imageExpression> </image> </band> </detail></jasperReport>[/code] And this is the full java code:public class JasperBAM { public static void main(String[] args) { try { List<BAMResult> bhs = BAMResult.getBAMResults(); JasperPrint jasperPrint = JasperFillManager.fillReport("JasperReports/results.jasper", null, new JRBeanCollectionDataSource(bhs)); OutputStream outputStream = new FileOutputStream(new File("BAM.pdf")); JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream); } catch (Exception ex) { Logger.getLogger(JasperBAM.class.getName()).log(Level.SEVERE, null, ex); } }}public class BAMResult { private String text; private BufferedImage image; public void settext(String text){this.text=text;} public String gettext(){return text;} public void setimage(){ try { image=ImageIO.read(new File("image.png")); } catch (IOException ex) { Logger.getLogger(BAMResult.class.getName()).log(Level.SEVERE, null, ex); } } public BufferedImage getimage() { return image; } public static List<BAMResult> getBAMResults() { try { List<BAMResult> brs = new ArrayList<>(); for(int i=1; i<100; i++) { BAMResult nt = new BAMResult(); nt.settext("record "+i); if (i % 20==0){ nt.setimage(); } brs.add(nt); } return brs; } catch (Exception ex) { Logger.getLogger(JasperBAM.class.getName()).log(Level.SEVERE, null, ex); return null; } }}[/code] I tried to set the "split type" of the detail band to "Immediate" but the space still appears.The problem is not related to the image field, I tried to put a text field in the place of the image and the problem is the same.The problem also appears in the preview of iReport Designer, I tested this with a direct connection to a database. Link to comment Share on other sites More sharing options...
Solution Tom C Posted June 4, 2021 Solution Share Posted June 4, 2021 This looks like a defect when JasperReports engine (JRL) calculates the remaining space on a page involving the RemoveLineWhenBlank property.The work around is to put your image in the second detail band and use band print when condition to determine whether the band will be called to display the image. This will avoid relying on RemoveLineWhenBlank property to shrink the band height causing the miscalculation. Link to comment Share on other sites More sharing options...
victor_38 Posted June 4, 2021 Author Share Posted June 4, 2021 Thank you Tchen, today I was ready to look into the source code as I couldn't find a solution to this problem.You saved me a lot of work. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now