本文介绍了为什么在Jasper Report 6.3中包装文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Jasper Report 6.3库将我的报告导出为PDF格式。当我输出的字符串的长度超过文本字段宽度jasper自动换行文本,但在这种情况下,一些文本覆盖如下图



我的文本字段属性

 弹出溢出,
剩余缩进:3px,
右缩进:8px,
拉伸类型:相对于最高对象

示例代码

 <?xml version =1.0encoding =UTF-8?> 
<! - 使用JasperReports库版本6.2.2创建与Jaspersoft Studio版本6.2.2.final - >
< jasperReport xmlns =http://jasperreports.sourceforge.net/jasperreportsxmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http: //jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsdname =item_wise_mrp_with_imagepageWidth =595pageHeight =842whenNoDataType =BlankPagecolumnWidth =575 leftMargin =10rightMargin =10topMargin =10bottomMargin =10whenResourceMissingType =Keyuuid =b7a946cd-ab42-4abe-b2f7-e616b2d38506>
< property name =com.jaspersoft.studio.data.defaultdataadaptervalue =One Empty Record/>
< parameter name =companyNameclass =java.lang.StringisForPrompting =false/>
< parameter name =companyAddressclass =java.lang.StringisForPrompting =false/>
< parameter name =quoteNumberclass =java.lang.IntegerisForPrompting =false/>
< parameter name =quoteDateclass =java.util.DateisForPrompting =false/>
< parameter name =customerNameclass =java.lang.StringisForPrompting =false/>
< parameter name =customerAddressclass =java.lang.String/>
< parameter name =emailIdclass =java.lang.StringisForPrompting =false/>
< parameter name =cityclass =java.lang.StringisForPrompting =false>
< parameterDescription><![CDATA []]>< / parameterDescription>
< / parameter>
< parameter name =mobileNoclass =java.lang.StringisForPrompting =false/>
< parameter name =clientMsgclass =java.lang.String/>
< parameter name =m_nrpclass =java.lang.StringisForPrompting =false/>
< parameter name =companyMobileclass =java.lang.StringisForPrompting =false/>
< parameter name =companyEmailclass =java.lang.StringisForPrompting =false/>
< queryString>
<![CDATA []]>
< / queryString>
< field name =totalAmountclass =java.lang.Double/>
< field name =itemCodeclass =java.lang.String/>
< field name =itemDescriptionclass =java.lang.String/>
< field name =quantityclass =java.lang.Integer/>
< field name =mrpclass =java.lang.Double/>
< field name =nrpclass =java.lang.Double/>
< variable name =tqtyclass =java.lang.Integercalculation =Sum>
< variableExpression><![CDATA [$ F {quantity}]]>< / variableExpression>
< / variable>
< variable name =tprcclass =java.lang.Doublecalculation =Sum>
< variableExpression><![CDATA [$ P {m_nrp} .equals(MRP)? $ F {} MRP:$ F {NRP}]]>< / variableExpression>
< / variable>
< variable name =tamtclass =java.lang.Doublecalculation =Sum>
< variableExpression><![CDATA [$ F {totalAmount}]]>< / variableExpression>
< / variable>
< background>
< band splitType =Stretch/>
< / background>
< detail>
< band height =96splitType =Stretch>
< property name =com.jaspersoft.studio.unit.heightvalue =pixel/>
< frame>
< reportElement x =0y =0width =575height =96uuid =7beb5f8d-7645-4156-95be-bef2533acba2>
< property name =com.jaspersoft.studio.unit.heightvalue =pixel/>
< / reportElement>
< box>
< leftPen lineWidth =0.25lineColor =#BFBFBF/>
< bottomPen lineWidth =0.25lineColor =#BFBFBF/>
< rightPen lineWidth =0.25lineColor =#BFBFBF/>
< / box>
< textField>
< reportElement stretchType =RelativeToBandHeightx =0y =0width =44height =96uuid =8b74ae61-7a6a-4cd7-a70d-857a5e434feb>
< property name =com.jaspersoft.studio.unit.widthvalue =pixel/>
< property name =com.jaspersoft.studio.unit.heightvalue =pixel/>
< / reportElement>
< box bottomPadding =2rightPadding =0>
< topPen lineWidth =0.0lineStyle =SolidlineColor =#000000/>
< bottomPen lineWidth =0.0lineStyle =SolidlineColor =#000000/>
< rightPen lineWidth =0.25lineStyle =SolidlineColor =#BFBFBF/>
< / box>
< textElement textAlignment =CenterverticalAlignment =Middle>
< font fontName =Calibrisize =11/>
< paragraph leftIndent =3rightIndent =5/>
< / textElement>
< textFieldExpression><![CDATA [$ V {REPORT_COUNT}]]>< / textFieldExpression>
< / textField>
< textField isStretchWithOverflow =trueisBlankWhenNull =true>
< reportElement stretchType =RelativeToBandHeightx =45y =0width =100height =96uuid =b6e44305-fe66-4c42-ac7e-c22827e26baf>
< property name =com.jaspersoft.studio.unit.xvalue =pixel/>
< property name =com.jaspersoft.studio.unit.widthvalue =pixel/>
< property name =com.jaspersoft.studio.unit.heightvalue =pixel/>
< / reportElement>
< box bottomPadding =2rightPadding =0>
< topPen lineWidth =0.0lineStyle =SolidlineColor =#000000/>
< bottomPen lineWidth =0.0lineStyle =SolidlineColor =#000000/>
< rightPen lineWidth =0.25lineStyle =SolidlineColor =#BFBFBF/>
< / box>
< textElement textAlignment =LeftverticalAlignment =Middle>
< font fontName =Calibrisize =11/>
< paragraph lineSpacingSize =0.0leftIndent =3rightIndent =8/>
< / textElement>
< textFieldExpression><![CDATA [$ P {customerAddress}]]>< / textFieldExpression>
< / textField>
< textField isStretchWithOverflow =trueisBlankWhenNull =true>
< reportElement stretchType =RelativeToBandHeightx =145y =0width =235height =96uuid =c7f1aaf5-c7fb-4e24-8283-c9d5a819feef>
< property name =com.jaspersoft.studio.unit.xvalue =pixel/>
< property name =com.jaspersoft.studio.unit.widthvalue =pixel/>
< property name =com.jaspersoft.studio.unit.heightvalue =pixel/>
< / reportElement>
< box bottomPadding =3rightPadding =0>
< topPen lineWidth =0.0lineStyle =SolidlineColor =#000000/>
< bottomPen lineWidth =0.0lineStyle =SolidlineColor =#000000/>
< rightPen lineWidth =0.25lineStyle =SolidlineColor =#BFBFBF/>
< / box>
< textElement textAlignment =LeftverticalAlignment =Middle>
< font fontName =Calibrisize =11/>
< paragraph lineSpacingSize =0.0leftIndent =3rightIndent =12/>
< / textElement>
< textFieldExpression><![CDATA [$ P {clientMsg}]]>< / textFieldExpression>
< / textField>
< textField>
< reportElement key =stretchType =RelativeToBandHeightx =380y =0width =40height =96uuid =70f88651-eefc-49df-898c-5a1eade29bac> ;
< property name =com.jaspersoft.studio.unit.xvalue =pixel/>
< property name =com.jaspersoft.studio.unit.widthvalue =pixel/>
< property name =com.jaspersoft.studio.unit.heightvalue =pixel/>
< / reportElement>
< box bottomPadding =2rightPadding =0>
< topPen lineWidth =0.0lineStyle =SolidlineColor =#000000/>
< bottomPen lineWidth =0.0lineStyle =SolidlineColor =#000000/>
< rightPen lineWidth =0.25lineStyle =SolidlineColor =#BFBFBF/>
< / box>
< textElement textAlignment =CenterverticalAlignment =Middle>
< font fontName =Calibrisize =11/>
< paragraph leftIndent =3rightIndent =5/>
< / textElement>
< textFieldExpression><![CDATA [$ F {quantity}]]>< / textFieldExpression>
< / textField>
< / frame>
< / band>
< / detail>
< / jasperReport>

这是一个示例代码。我使用了



添加字体扩展名之后运行报告,问题得以解决



当您跑出JasperSoft Studio,如果你喜欢使用Calibri字体,你需要创建一个字体扩展jar(添加到classpath),否则切换字体。

I use Jasper Report 6.3 library for exporting my report to PDF format. When I export if string length more than text field width jasper auto wrap text but in this case some text override like below picture

My text field properties:

stretch with overflow,
left indent: 3px,
right indent: 8px,
stretch type: Relative to Tallest object

Sample code

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.2.final using JasperReports Library version 6.2.2  -->
<!-- 2016-09-03T20:46:49 -->
<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="item_wise_mrp_with_image" pageWidth="595" pageHeight="842" whenNoDataType="BlankPage" columnWidth="575" leftMargin="10" rightMargin="10" topMargin="10" bottomMargin="10" whenResourceMissingType="Key" uuid="b7a946cd-ab42-4abe-b2f7-e616b2d38506">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <parameter name="companyName" class="java.lang.String" isForPrompting="false"/>
    <parameter name="companyAddress" class="java.lang.String" isForPrompting="false"/>
    <parameter name="quoteNumber" class="java.lang.Integer" isForPrompting="false"/>
    <parameter name="quoteDate" class="java.util.Date" isForPrompting="false"/>
    <parameter name="customerName" class="java.lang.String" isForPrompting="false"/>
    <parameter name="customerAddress" class="java.lang.String"/>
    <parameter name="emailId" class="java.lang.String" isForPrompting="false"/>
    <parameter name="city" class="java.lang.String" isForPrompting="false">
        <parameterDescription><![CDATA[]]></parameterDescription>
    </parameter>
    <parameter name="mobileNo" class="java.lang.String" isForPrompting="false"/>
    <parameter name="clientMsg" class="java.lang.String"/>
    <parameter name="m_nrp" class="java.lang.String" isForPrompting="false"/>
    <parameter name="companyMobile" class="java.lang.String" isForPrompting="false"/>
    <parameter name="companyEmail" class="java.lang.String" isForPrompting="false"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="totalAmount" class="java.lang.Double"/>
    <field name="itemCode" class="java.lang.String"/>
    <field name="itemDescription" class="java.lang.String"/>
    <field name="quantity" class="java.lang.Integer"/>
    <field name="mrp" class="java.lang.Double"/>
    <field name="nrp" class="java.lang.Double"/>
    <variable name="tqty" class="java.lang.Integer" calculation="Sum">
        <variableExpression><![CDATA[$F{quantity}]]></variableExpression>
    </variable>
    <variable name="tprc" class="java.lang.Double" calculation="Sum">
        <variableExpression><![CDATA[$P{m_nrp}.equals( "MRP" )? $F{mrp}:$F{nrp}]]></variableExpression>
    </variable>
    <variable name="tamt" class="java.lang.Double" calculation="Sum">
        <variableExpression><![CDATA[$F{totalAmount}]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="96" splitType="Stretch">
            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
            <frame>
                <reportElement x="0" y="0" width="575" height="96" uuid="7beb5f8d-7645-4156-95be-bef2533acba2">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <box>
                    <leftPen lineWidth="0.25" lineColor="#BFBFBF"/>
                    <bottomPen lineWidth="0.25" lineColor="#BFBFBF"/>
                    <rightPen lineWidth="0.25" lineColor="#BFBFBF"/>
                </box>
                <textField>
                    <reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="44" height="96" uuid="8b74ae61-7a6a-4cd7-a70d-857a5e434feb">
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                    </reportElement>
                    <box bottomPadding="2" rightPadding="0">
                        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.25" lineStyle="Solid" lineColor="#BFBFBF"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font fontName="Calibri" size="11"/>
                        <paragraph leftIndent="3" rightIndent="5"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement stretchType="RelativeToBandHeight" x="45" y="0" width="100" height="96" uuid="b6e44305-fe66-4c42-ac7e-c22827e26baf">
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                    </reportElement>
                    <box bottomPadding="2" rightPadding="0">
                        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.25" lineStyle="Solid" lineColor="#BFBFBF"/>
                    </box>
                    <textElement textAlignment="Left" verticalAlignment="Middle">
                        <font fontName="Calibri" size="11"/>
                        <paragraph lineSpacingSize="0.0" leftIndent="3" rightIndent="8"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$P{customerAddress}]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                    <reportElement stretchType="RelativeToBandHeight" x="145" y="0" width="235" height="96" uuid="c7f1aaf5-c7fb-4e24-8283-c9d5a819feef">
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                    </reportElement>
                    <box bottomPadding="3" rightPadding="0">
                        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.25" lineStyle="Solid" lineColor="#BFBFBF"/>
                    </box>
                    <textElement textAlignment="Left" verticalAlignment="Middle">
                        <font fontName="Calibri" size="11"/>
                        <paragraph lineSpacingSize="0.0" leftIndent="3" rightIndent="12"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$P{clientMsg}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement key="" stretchType="RelativeToBandHeight" x="380" y="0" width="40" height="96" uuid="70f88651-eefc-49df-898c-5a1eade29bac">
                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                    </reportElement>
                    <box bottomPadding="2" rightPadding="0">
                        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.25" lineStyle="Solid" lineColor="#BFBFBF"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font fontName="Calibri" size="11"/>
                        <paragraph leftIndent="3" rightIndent="5"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$F{quantity}]]></textFieldExpression>
                </textField>
            </frame>
        </band>
    </detail>
</jasperReport>

This is a sample code. I used Jasper Studio. To reproduce this error enter below inputs

customerAddress: ALD-CHR-769L250X190
clientMsg: Bottle Trap( With Internal Partition) 32mm Size With 250mm & 190mm Long Wall Connection Pipes & Wall Flange

How can I solve this problem?

解决方案

Yes this is a usual font-extension problem, I managed to reproduce your issue and adding font extension it got solved.

This is how to add font-extension in JasperSoft Studio, I had these settings

Running the report after adding the font-extension the problem was solved

When you run outside of JasperSoft Studio, you need to create a font-extension jar (add to classpath) if you like to use the Calibri font, otherwise switch the font.

这篇关于为什么在Jasper Report 6.3中包装文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 06:16