JasperReport 内容溢出跨页打印显示问题解决方案

解决JasperReport打印模板detail内容跨页问题
本文介绍了在使用JasperReport开发打印功能时遇到的一个问题:detail部分内容溢出导致在新页重复打印。作者通过一周的探索,发现在detail的Bandproperties中修改SplitType属性为Prevent,成功解决了内容跨页打印的问题。调整后,溢出内容会整体出现在第二页,避免了重复打印。

问题现象

目前在接到需求需要开发一个打印功能,打印功能使用jasper report技术设计打印模板,在时间的过程中由于detail中的内容溢出,每当溢出的内容在最后一行的时候就会在下一页显示剩余内容,没有溢出的内容则显示重复。
在这里插入图片描述
问题如下

解决思路

能不能让溢出的部分整体在第二页打印

解决方案

经过自己一个礼拜的摸索,最后想到是不是与这个detail整体的属性有关系呢,因此在编辑器中找到detail运输查看他的属性
在这里插入图片描述
果然detail也有自己的属性
在这里插入图片描述
我尝试的将 Split Type 从 Stretch 修改为 Prrvent的再次尝试

在这里插入图片描述
测试的过程中发现果然解决了这个问题
在这里插入图片描述
对比第一幅图可以发现,0014行已经不再重复打印了。而且原本在第一页打印的内容目前已经在第二页打印了。

总结

点击detail 将 Band properties 的
Split Type 属性修改为Prrvent即可实现不夸页打印

<?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.5.0.final using JasperReports Library version 6.5.0 --> <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="CE74O1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="560" leftMargin="17" rightMargin="17" topMargin="20" bottomMargin="20" whenResourceMissingType="Error" uuid="f570145a-65a9-4e7e-ba6e-5520ee8382ef"> <property name="net.sf.jasperreports.export.pdf.exclude.key.TransparentImage" value=""/> <property name="net.sf.jasperreports.export.pdf.tagged" value="true"/> <property name="net.sf.jasperreports.export.pdfa.conformance" value="pdfa1a"/> <property name="net.sf.jasperreports.export.pdfa.icc.profile.path" value="C:\project\JavaProject\MOADoms\fonts\AdobeRGB1998.icc"/> <property name="ireport.scriptlethandling" value="0"/> <property name="ireport.encoding" value="UTF-8"/> <property name="ireport.zoom" value="2.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <property name="net.sf.jasperreports.export.pdf.force.linebreak.policy" value="true"/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/> <property name="com.jaspersoft.studio.unit." value="pixel"/> <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/> <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/> <property name="net.sf.jasperreports.export.xls.font.size.fix.enabled" value="true"/> <import value="net.sf.jasperreports.engine.*"/> <import value="java.util.*"/> <import value="net.sf.jasperreports.engine.data.*"/> <import value="jcs.doms.JR.JR_Common.*"/> <style name="myfont" isDefault="true" fontName="標楷體" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/> <parameter name="parameter0" class="java.lang.String" isForPrompting="false"/> <parameter name="parameter1" class="java.lang.String" isForPrompting="false"/> <queryString> <![CDATA[SELECT BD_RECENO,BD_RECEDATE,BD_FINALDTE,BD_COMPDATE, BD_ATTRCODE,BD_THEME,IP_DEPTNAME AS BD_CHARGEDPNM, BD_CHARGEPE_NM, BD_CHARGEDP, CASE WHEN (BD_SENDTYPE IS NOT NULL AND BD_SENDTYPE = '1') THEN '發文歸檔' ELSE (CASE WHEN (BD_FILETYPE IS NOT NULL AND BD_FILETYPE = '1') THEN '存查歸檔' ELSE '' END) END AS ETYPE , '一般' AS ATTRCODE FROM DOMS.DOC_BASEDATA_VIEW JOIN DOMS.DPT_INSEDEPT ON BD_CHARGEDP=IP_DEPTCODE WHERE ( BD_SENDTYPE > '' ) AND BD_HANDSTAT<>'4' AND BD_ORIGIN <= '5' AND (BD_CHARGEDP NOT IN ('B1','B2','B3','B4','B5','B6','B7','B8','B9','D0','E0')) AND (BD_ATTRCODE IN ('A','P','Q')) AND (BD_SPECDOC <> 'Y' OR BD_SPECDOC IS NULL) AND (BD_APPLYDATE IS NULL OR BD_APPLYDATE = 0) AND BD_HANDSTAT <> '4' AND (BD_COMPDATE >= 990101 AND BD_COMPDATE <= 991223 ) AND IP_DEPTTYPE='H' AND BD_DECISION = '1' ORDER BY BD_CHARGEDP ASC,BD_SUBDEPT ASC,BD_CHARGEPE ASC]]> </queryString> <field name="BD_RECENO" class="java.lang.String"/> <field name="BD_DESIDATE" class="java.lang.Integer"/> <field name="BD_CHARGEDP_NM" class="java.lang.String"/> <field name="IP_DEPTNAME" class="java.lang.String"/> <field name="BD_THEME" class="java.lang.String"/> <field name="IP_DEPTCODE" class="java.lang.String"/> <group name="chargedp" isStartNewPage="true"> <groupExpression><![CDATA[$F{IP_DEPTCODE}]]></groupExpression> <groupHeader> <band splitType="Stretch"/> </groupHeader> <groupFooter> <band splitType="Stretch"/> </groupFooter> </group> <background> <band splitType="Stretch"/> </background> <title> <band splitType="Stretch"/> </title> <pageHeader> <band height="66" splitType="Prevent"> <textField isBlankWhenNull="false"> <reportElement key="textField" style="myfont" positionType="FixRelativeToBottom" stretchType="RelativeToTallestObject" x="0" y="0" width="560" height="36" printWhenGroupChanges="chargedp" uuid="9d7591cc-64cd-4c67-b135-7861521057c0"> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> </reportElement> <box padding="1"> <pen lineWidth="1.0"/> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle" markup="html"> <font size="16"/> </textElement> <textFieldExpression><![CDATA[$P{parameter1} + $F{IP_DEPTNAME} + "決行案件清單"]]></textFieldExpression> </textField> <staticText> <reportElement key="staticText-6" style="myfont" x="0" y="36" width="40" height="30" uuid="679b43bd-58b2-4140-b959-1a989e5d0903"> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> </reportElement> <box> <pen lineWidth="1.0"/> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <text><![CDATA[序號]]></text> </staticText> <staticText> <reportElement key="staticText-7" style="myfont" stretchType="RelativeToTallestObject" x="40" y="36" width="110" height="30" uuid="11193ff5-3b0a-4abb-a355-c55120dcb69f"> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> </reportElement> <box> <pen lineWidth="1.0"/> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <text><![CDATA[承辦單位]]></text> </staticText> <staticText> <reportElement key="staticText-8" style="myfont" x="150" y="36" width="70" height="30" uuid="44c86de7-0182-4d3e-ba5e-093e53523b80"> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> </reportElement> <box> <pen lineWidth="1.0"/> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <text><![CDATA[決行日期]]></text> </staticText> <staticText> <reportElement key="staticText-9" style="myfont" x="220" y="36" width="90" height="30" uuid="69e41a58-7a8c-45f2-a77f-0dbce7ae80e3"> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> </reportElement> <box> <pen lineWidth="1.0"/> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <text><![CDATA[文號]]></text> </staticText> <staticText> <reportElement key="staticText-10" style="myfont" stretchType="RelativeToBandHeight" x="310" y="36" width="250" height="30" uuid="01ff2c2a-c92d-4af3-93fd-1a5e6a2ff2c5"> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> </reportElement> <box> <pen lineWidth="1.0"/> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <text><![CDATA[主旨]]></text> </staticText> </band> </pageHeader> <columnHeader> <band splitType="Stretch"> <property name="com.jaspersoft.studio.layout"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </band> </columnHeader> <detail> <band height="40" splitType="Prevent"> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField isStretchWithOverflow="true" isBlankWhenNull="false"> <reportElement style="myfont" positionType="Float" stretchType="RelativeToBandHeight" x="0" y="0" width="40" height="40" isPrintWhenDetailOverflows="true" printWhenGroupChanges="chargedp" uuid="8d4293d3-f655-4b51-b090-8c56e55f3cda"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0"> <pen lineWidth="1.0"/> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <textFieldExpression><![CDATA[$V{chargedp_COUNT}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" isBlankWhenNull="false"> <reportElement style="myfont" positionType="Float" stretchType="RelativeToBandHeight" x="40" y="0" width="110" height="40" isPrintWhenDetailOverflows="true" uuid="220e0556-8315-487d-bbef-cfc3643e516c"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <box> <pen lineWidth="1.0"/> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <textFieldExpression><![CDATA[$F{BD_CHARGEDP_NM}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" isBlankWhenNull="false"> <reportElement style="myfont" positionType="Float" stretchType="RelativeToBandHeight" x="150" y="0" width="70" height="40" isPrintWhenDetailOverflows="true" uuid="860e81bd-88fb-4d81-8cb7-0185af1963be"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <box> <pen lineWidth="1.0"/> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <textFieldExpression><![CDATA[$F{BD_DESIDATE}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" isBlankWhenNull="false"> <reportElement style="myfont" positionType="Float" stretchType="RelativeToBandHeight" isPrintRepeatedValues="false" x="220" y="0" width="90" height="40" isPrintWhenDetailOverflows="true" uuid="743d11c0-cf98-4343-8bd9-d6ba722f5366"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <box> <pen lineWidth="1.0"/> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="12"/> </textElement> <textFieldExpression><![CDATA[$F{BD_RECENO}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" isBlankWhenNull="false"> <reportElement style="myfont" positionType="Float" stretchType="RelativeToBandHeight" x="310" y="0" width="250" height="40" isPrintWhenDetailOverflows="true" uuid="5c1f90eb-81ed-4cc8-b016-63566a174541"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <box topPadding="3" leftPadding="0" bottomPadding="3" rightPadding="0"> <pen lineWidth="1.0"/> <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Left" verticalAlignment="Middle"> <font size="12"/> <paragraph lineSpacing="Single" lineSpacingSize="1.6"/> </textElement> <textFieldExpression><![CDATA["\n" + $F{BD_THEME} + "\n"]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band splitType="Stretch"/> </columnFooter> <pageFooter> <band splitType="Stretch"/> </pageFooter> <summary> <band splitType="Stretch"/> </summary> </jasperReport> 還是沒辦法
最新发布
10-16
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值