TIBCOSoftware / jasperreports

JasperReports® - Free Java Reporting Library
https://community.jaspersoft.com/downloads/community-edition/
GNU Lesser General Public License v3.0
1.03k stars 396 forks source link

PDF Export: Stretch - truncation instead of stretch #429

Closed lenoch7 closed 5 months ago

lenoch7 commented 5 months ago

I have very weird problem with stretching. I created very simple jrxml to demonstrate this problem (is attached), in reality DataSource is used of course. I am using Linux and I tested it with version 6.20.5 and 6.21.2.

stretch-truncation-reports.zip

<?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="SimpleStretchTest"
  pageWidth="595"
  pageHeight="842"
  leftMargin="20"
  rightMargin="20"
  topMargin="30"
  bottomMargin="30"
  uuid="a09b55bb-d25f-4b19-a103-ef479d2e3c41"
>
  <detail>
    <band height="600">
      <!-- Wrong, truncation to ab-abcdefghijkl.mnopqrstuvwxyz012345 (3 lines) -->
      <textField textAdjust="StretchHeight">
        <reportElement x="0" y="0" width="100" height="16" uuid="4f38e741-082f-424e-a035-3b7568005a98"/>
        <textElement>
          <font size="12"/>
        </textElement>
        <textFieldExpression><![CDATA["ab-abcdefghijkl.mnopqrstuvwxyz0123456789"]]></textFieldExpression>
      </textField>
    </band>
  </detail>
</jasperReport>

The problem here is that text is truncated to ab-abcdefghijkl.mnopqrstuvwxyz012345 (3 lines) (6789 is missing). I attached pdf file too.

It seems like there is a problem with - (dash) or . (dot) characters, because:

IMHO, there is a some problem with height calculation in context of BreakInterator.

I hope, I am not completely wrong (I mean jrxml file), but if I tested similar/same jrxml file (textAdjust vs isStretchWithOverflow) with very old version 4.5.0 it works as is expected (or at least it seems like it).

dadza commented 5 months ago

Set the net.sf.jasperreports.export.pdf.force.linebreak.policy property to true to make sure that the same line break policy is applied when measuring the texts and on PDF exporting.

Also, if you need to use a font extension with a embedded PDF font (for instance DejaVu Sans from jasperreports-fonts) to ensure that the font metrics used for text measuring are consistent with the PDF export.

lenoch7 commented 5 months ago

Thank you for quick answer. This configuration solves the problem.

I am sorry for stupid question and for creating this issue (now I see it in JRPdfExporter javadoc too). I knew about difference between AWT measurement and PDF exporting, but I completely missed ForceLineBreakPolicy. I am sorry again.