zizul Posted January 7, 2010 Share Posted January 7, 2010 Hi. I've got a problem, which I've been struggling with for quite some time now. Finally I've decided to write about it on the forum, since I don't have a clue what to do about it anymore.Hope you could figure somthing out. Problem:There is a textfield with option "Stretch with overflow". It is populated dynamically from datasource objects, passed to the subreport from the main report. A text somtimes is longer than textfield's width so it wraps and streches vertically accordingly. Most of the time it streches correctly, to the number of lines of text. But sometimes it adds extra blank line (space) under the text. Things checked:- text is trimmed (checked for extra whitespaces and new line characters)- text is not ending close to the border of textfield Tried:- changing different fonts, encodings- adding padding to textfield- changing textfield width and height to smaller and bigger (even to 0)- changing Position type and Strech type of the textfield and surrounding elements- changing text alignment- changing jasperreports version- adding different text properties like net.sf.jasperreports.text.truncate.at.char- setting different exporter properties like JRPdfExporterParameter.FORCE_LINEBREAK_POLICY I will post any additional information if needed.Looking forward to any comments and suggestions. Regards,Kacper Code:<?xml version="1.0" encoding="UTF-8"?><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="subGroupSubreport" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0"> <parameter name="episode" class="pl.psnc.domain.wtc.core.episode.Episode"/> <parameter name="groupSummarySubreport" class="net.sf.jasperreports.engine.JasperReport"/> <parameter name="isInjuryMap" class="java.lang.Boolean"/> <queryString> <![CDATA[]]> </queryString> <field name="shortDisplayName" class="java.lang.String"/> <field name="attributeUIs" class="java.util.Set"/> <field name="attributeOids" class="java.util.Collection"/> <field name="displayIndex" class="java.lang.Integer"/> <sortField name="displayIndex"/> <variable name="date" class="java.lang.String" resetType="None"> <variableExpression><![CDATA[($F{attributeOids}.size() > 0 ? ((String) new ArrayList($P{episode}.getResultsDatesInMilisecondsForAttributes($F{attributeOids})).get(0)) : "")]]></variableExpression> </variable> <variable name="multi" class="java.lang.String"> <variableExpression><![CDATA[($F{attributeOids}.size() > 0 ? ((String) new ArrayList($P{episode}.getResultsMultiNamesForAttributes($F{attributeOids})).get(0)) : "")]]></variableExpression> </variable> <variable name="test" class="java.lang.Integer" incrementType="Column"/> <variable name="dates" class="java.util.List"> <variableExpression><![CDATA[new java.util.ArrayList($P{episode}.getResultsDatesInMilisecondsForAttributes($F{attributeOids}))]]></variableExpression> </variable> <detail> <band height="31" splitType="Stretch"> <frame> <reportElement positionType="Float" isPrintRepeatedValues="false" x="0" y="14" width="255" height="17" isRemoveLineWhenBlank="true"/> <box leftPadding="0"> <pen lineWidth="0.0" lineColor="#CCCC00"/> <topPen lineWidth="0.0" lineColor="#CCCC00"/> <leftPen lineWidth="0.0" lineColor="#CCCC00"/> <bottomPen lineWidth="0.0" lineColor="#CCCC00"/> <rightPen lineWidth="0.0" lineColor="#CCCC00"/> </box> <subreport isUsingCache="false"> <reportElement positionType="Float" x="0" y="0" width="255" height="17" isRemoveLineWhenBlank="true"/> <subreportParameter name="episode"> <subreportParameterExpression><![CDATA[$P{episode}]]></subreportParameterExpression> </subreportParameter> <subreportParameter name="multi"> <subreportParameterExpression><![CDATA[$V{multi}]]></subreportParameterExpression> </subreportParameter> <subreportParameter name="isInjuryMap"> <subreportParameterExpression><![CDATA[new Boolean($P{isInjuryMap}.booleanValue() && $V{REPORT_COUNT}.intValue() == 1)]]></subreportParameterExpression> </subreportParameter> <subreportParameter name="date"> <subreportParameterExpression><![CDATA[$V{date}]]></subreportParameterExpression> </subreportParameter> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{attributeUIs})]]></dataSourceExpression> <subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{groupSummarySubreport}]]></subreportExpression> </subreport> </frame> <textField isStretchWithOverflow="true" isBlankWhenNull="false"> <reportElement positionType="Float" x="0" y="0" width="255" height="14" isRemoveLineWhenBlank="true" forecolor="#5D99B1"> <printWhenExpression><![CDATA[new Boolean(!$P{isInjuryMap}.booleanValue() || ($P{isInjuryMap}.booleanValue() && $V{REPORT_COUNT}.intValue() > 1))]]></printWhenExpression> </reportElement> <box leftPadding="8" rightPadding="15"> <pen lineWidth="0.25" lineColor="#0000CC"/> <topPen lineWidth="0.25" lineColor="#0000CC"/> <leftPen lineWidth="0.25" lineColor="#0000CC"/> <bottomPen lineWidth="0.25" lineColor="#0000CC"/> <rightPen lineWidth="0.25" lineColor="#0000CC"/> </box> <textElement textAlignment="Left"> <font fontName="DejaVuSansMono" size="12" isBold="true" pdfEncoding="Cp1250"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{shortDisplayName}.trim().replaceAll("\r","").replaceAll("\n","")]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" isBlankWhenNull="false"> <reportElement positionType="Float" x="0" y="0" width="210" height="14" isRemoveLineWhenBlank="true" forecolor="#5D99B1"> <property name="net.sf.jasperreports.text.truncate.at.char" value="true"/> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/> <printWhenExpression><![CDATA[new Boolean($P{isInjuryMap}.booleanValue() && $V{REPORT_COUNT}.intValue() == 1)]]></printWhenExpression> </reportElement> <box leftPadding="8" rightPadding="15"> <pen lineWidth="0.25" lineColor="#0000CC"/> <topPen lineWidth="0.25" lineColor="#0000CC"/> <leftPen lineWidth="0.25" lineColor="#0000CC"/> <bottomPen lineWidth="0.25" lineColor="#0000CC"/> <rightPen lineWidth="0.25" lineColor="#0000CC"/> </box> <textElement textAlignment="Left"> <font fontName="DejaVuSansMono" size="12" isBold="true" pdfFontName="Helvetica" pdfEncoding="Cp1250"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$F{shortDisplayName}.trim().replaceAll("\r","").replaceAll("\n","")]]></textFieldExpression> </textField> </band> </detail></jasperReport> Link to comment Share on other sites More sharing options...
lucianc Posted January 7, 2010 Share Posted January 7, 2010 In which output format does this happen?Regards,Lucian Link to comment Share on other sites More sharing options...
zizul Posted January 7, 2010 Author Share Posted January 7, 2010 Hi Lucian .Thanks for the reply.The report is exported to pdf file.Regards,Kacper Link to comment Share on other sites More sharing options...
lucianc Posted January 7, 2010 Share Posted January 7, 2010 Have you seen the FAQ at http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/faq.html?group_id=252#FAQ25? Link to comment Share on other sites More sharing options...
zizul Posted January 13, 2010 Author Share Posted January 13, 2010 Yes, I've seen it and tried using different fonts.But when you pointed it out again, it got me thinking and I've found the solution. The problem was with the bold fonts. When I was checking bold option on textfield or using <b> tag with markup option on part of the text in texfield, the problem was occurring.I specified fonts in fonts.xml file like that: <bean id="DejaVuSans" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily"> <property name="name" value="DejaVuSans"/> <property name="normal" value="./fonts/DejaVuSans.ttf"/> <property name="pdfEncoding" value="Identity-H"/> <property name="pdfEmbedded" value="true"/> </bean>As a diagnosed later, I was missing the declaration of bold font: <property name="bold" value="./fonts/DejaVuSans-Bold.ttf"/>Just like it was said in FAQ answer, the JVM must have been silently using some default font for bold, which caused the problem. Anyway, thanks a lot Lucian for the clue.Best regards,Kacper Link to comment Share on other sites More sharing options...
shivenderd Posted July 27, 2010 Share Posted July 27, 2010 Hi,I see a problem similar to this. We do the following operations:1 - We have a textfield in the jrxml that has isStretchWithOverflow="true" attribute set. 2 -Generate the JasperPrint instance by calling JasperFillManager.fillReport() method3 - Replace the PDFFontname and encoding by calling individual methods on the fields:((JRTemplateText)text.getTemplate()).setPdfFontName()4 - We return the jasperprint instance to JRViewer and the same is used by the PDFexporter. If we have japanese charecters, at step-3 we set the pdffont name to HeiseiKakuGo-W5 and pdfencoding to UniJIS-UCS2-H.When we execute this in Windows environment, it is working fine and displaying the japanese charecters in both JRViewer and also in the Exported PDF.When we execute this in Solaris Japanese locale OS, it is truncating text both in JRViewer and exported PDF. if I give extra line breaks at end of the text, then the text is displayed completley. I am sure it must be the font metrics problem when the report is being generated. Can you suggest any way to solve this problem? We would like to see the consistent behavior in both solaris and windows environment Link to comment Share on other sites More sharing options...
alekhyareddym6 Posted March 14, 2015 Share Posted March 14, 2015 Hi Kacper , I am facing similar problem on using strech with overflow for textfield. Can you please tell me if you get any solutionRegards,Alekhya 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