Jump to content

Generated PDF text truncated (last line removed)


alexsvecencu

Recommended Posts

Hello,

I am generating a PDF report with jasper reports version 6.1.0 from my web app. The last line of the text field is always truncated. After doing some research on the site I have done the following:

  • added a font extension (it is correctly loaded, no errors are thrown, changes are visible when adding the font extension to the classpath and I have even debbuged SimpleFontExtensionsRegistryFactory , to see that my font is correctly loaded)
  • added pdf force linebreak policy in the jrxml
  • viewing the report in JasperViewer shows the report as I expect (see attached image)
  • viewing the generated pdf removes the last line of the text field (see attached image)

It seems to me that this is only happening when I add the lineSpacing attribute to the text field (important feature for the report I am working on).

Could someone please point me in the right direction to solving this issue?

Thank you,

jasper_viewer_truncate.JPG.4741343f1af80037c5aa19d0a00c3c3b.JPG

 

jasper_pdf_truncate.JPG.ee44981e2d24b43d91b16da9b55f70f5.JPG

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="sampleTemplate" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5929a4e7-a04a-4e0d-b08e-708460b659c6">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="net.sf.jasperreports.export.pdf.force.linebreak.policy" value="true"/>
<field name="sample.text" class="java.lang.String">
  <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<detail>
  <band height="428" splitType="Stretch">
   <textField isStretchWithOverflow="true">
    <reportElement key="" positionType="Float" x="-20" y="0" width="595" height="30" uuid="2ca259b2-50de-4ae1-ac2e-4bfbd7824305"/>
    <textElement markup="html">
     <font fontName="Arial Unicode MS" size="11" isPdfEmbedded="true"/>
     <paragraph lineSpacing="Proportional" lineSpacingSize="0.5"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{sample.text}]]></textFieldExpression>
   </textField>
   <staticText>
    <reportElement positionType="Float" x="-20" y="30" width="595" height="20" uuid="2a9ee89c-e1a0-48e8-91ee-4a3dcdc9699b"/>
    <textElement textAlignment="Center">
     <font fontName="Arial Unicode MS" size="11"/>
    </textElement>
    <text><![CDATA[EMPTY TEXT FIELD]]></text>
   </staticText>
  </band>
</detail>
</jasperReport>

<?xml version="1.0" encoding="UTF-8"?>

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Updated jasperreports dependency to 6.2.1 and the behavior is the same. Changing the height of text area won't help (isStretchWithOverflow is set on that textfield anyway) and using a different font or decreasing the font size is not an option as these are the requirements for the report I am creating...

My real issue is actually reducing the line spacing. I need to fit a pretty large amount of text in a limited space (I have some text fields that need to fit exactly in one page and they must stretch depending on the content). The requirement is to reduce the line spacing as much as possible so I am using the proportional option with 0.5. I've tried using Fixed, but anything below lineSpacingSize 9 for fixed will cause the problem again. Is there anything I am doing wrong related to this?

Link to comment
Share on other sites

Most likely you are right and something is wrong in the way the font is loaded/available space is calculated for rendering the text. I haven't managed to isolate where the issue is coming from but I have found a workaround. My textfields are specified to use html markup so what I have done is added a <br> to the end of each expression.

For example: <textFieldExpression><![CDATA[$F{sample.text}+"<br>"]]></textFieldExpression>This forces the last line to appear for all the tests I've ran. Hope this proves useful for others having the same issue.

Link to comment
Share on other sites

  • 2 months later...

Unfortunately, I can confirm the issue. I have the same problem if I have texts containing the letter ß (while umlauts don't seem to cause problems interestingly). It is important to note that the preview inside Jaspersoft Studio is fine, problem occurs only when you export the report to file. Docx and pdf are both affected, while html is not. In docx, I can see that the textfield or area or what ever is not large enough. If I make it larger, the text appears. Also, the issue seems to be related to Arial, other fonts are fine. I personally use version 5.22 of Arial, if someone could name a version that works, I'd have a workaround at least. Adding a linebreak is not an option for me as it can cause empty pages. Also, due to my enterprises policy, I can't switch from Arial.

As always in cases like this, the issue is urgent for me...

EDIT: I tried Jaspersoft 6.1.1 and 6.3, as library and from inside Studio.

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...