Jump to content
We've recently updated our Privacy Statement, available here ×

Why so much unused space, engine is skipping to a new page even if a lot of data could fit on the current page


victor_38
Go to solution Solved by Tom C,

Recommended Posts

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.

BuAo9.png

 

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

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

  • Solution

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.

a_2.thumb.png.18173cf81c8368082b91b42f9b573dba.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...