Text wrapping issue in generated pdf file

2019-01-26 16:42发布

问题:

I have an issue related to wrapping of text in pdf format. For all the formats like xls,rtf, and pptx the report works fine,however in pdf some text gets wrapped i.e. some letters of the text especially the last few letters gets printed in the next line. I have tried almost all the options in the properties for that text. The only way I could reduce the effect was by changing the pdf font name to times roman for those text. However even this does not work in some case.

The snippet contains problem TextField:

<textField  isBlankWhenNull="true">
    <reportElement positionType="Float" x="560" y="0" width="60" height="20"/>
    <box leftPadding="2">
        <pen lineWidth="0.5"/>
        <topPen lineWidth="0.5"/>
        <leftPen lineWidth="0.5"/>
        <bottomPen lineWidth="0.5"/>
        <rightPen lineWidth="0.5"/>
    </box>
    <textElement>
        <font fontName="Arial Unicode MS"  isPdfEmbedded="false"/>
    </textElement>
    <textFieldExpression class="java.lang.String"><![CDATA[$F{CustState}]]>
    </textFieldExpression>
</textField>

I would be very grateful if you share some solution for this. Thanks...

P.s I get this issue when i generate the report from Ireport 4.0.2

回答1:

First, use Font Extensions. Your issue is very likely because JasperReports (iText) isn't using the font that you want it to be using when generating the PDF. Font Extensions solve this.

Second, it's possible that you're encountering an issue that got fixed. The JasperReports 4.1.1 Change Log includes this:

the net.sf.jasperreports.export.pdf.force.linebreak.policy configuration property is now deprecated as the PDF text rendering code was refactored so that text is rendered exactly like in AWT



回答2:

You can avoid this by adding a space end of the text.I am also using jasper4.0.2 and It worked for me.



回答3:

Some elements (TextField or StaticText) can increase its height depends on stretch type and stretch with overflow properties. But element's width can not be changed without programming.

The quote from iReport Ultimate Guide:

Stretch type - This attribute defines how to calculate the element height during the print elaboration; the three possible values are as follows:
  • NoStretch - This is the pre-defined stretch type, and it dictates that the element height should be kept equal.
  • RelativeToBandHeight - The element height is increased proportionally to the increasing size of the band; this is useful for vertical lines that simulate table borders.
  • RelativeToTallestObject - The element modifies its height according to the deformation of the nearest element: this option is also used with the element group, which is an element group mechanism not managed by iReport

    Stretch with overflow - When it is selected, this option allows the textfield to adapt vertically to the content, if the element is not sufficient to contain all the text line
  • You can use, for example ColumnBuilder class from DynamicJasper API to set column width.

    You can also read this discussion.



    回答4:

    For text wrapping issue in pdf export in iReport 4.0.2:

    Convert your fonts as Jar, then add as external jar, definitely it will work.

    In iReport designer:

    Step 1) Tool -> Option -> Fonts -> Install your fonts

    Step 2) Select that font -> click on export as extension [ make it as JAR ]

    Step 3) Go to Classpath -> click on ADD Jar -> add your font jar -> OK

    Now preview the report.