Jump to content
We've recently updated our Privacy Statement, available here ×
  • Why is my text not displayed correctly in PDF?


    djohnson53
    • Version: v5.1, v5.0, v4.8, v4.7, v4.6, v4.5 Product: JasperReports® Library

    When your PDF reports contain texts that do not stretch properly (i.e. are truncated or leave some space unused), or have improper line spacing, the probable cause is that the Java/AWT and PDF fonts used for the report text elements do not match.

    The fontName attribute of a report text element is resolved to a Java/AWT font which is used at report fill time to compute several text layout attributes including how much does the element need to stretch in order to accommodate its contents, or what part of the text does fit if the element is not allowed to stretch. When the report gets exported to PDF, the text layout parameters computed at fill time are used along with a PDF font determined by the pdfFontName attribute of the text element. If the PDF font metrics are not identical to the metrics of the Java/AWT font, then the text in the PDF output might not fit entirely or might not use the entire space reserved for the text element.

    Because of this, the JasperReports engine works by the contract that the Java/AWT font (specified using the fontName attribute) and the PDF font (specified using the pdfFontName attribute) resolve to the same physical font (or to fonts that have identical metrics).

    One thing to play attention to is making sure that the fonts set in the report via fontName attributes are actually available in the Java VM, because AWT silently uses the default font when a specific font cannot be loaded.

    When confronted with such issues it is useful to display the report in JasperViewer, as the viewer would use the same Java/AWT fonts that were involved in computing the text layout attributes (assuming that the fonts are still available in the JVM). If the report displays properly in JasperViewer, then it is very likely that the PDF fonts do not match the Java fonts.

    One more possible cause of text not displaying properly in PDF (even when the fonts match) is the fact that the default AWT and PDF line breaking policies differ slightly. The solution to this issue is to instruct the PDF exporter to use the AWT line breaking policy. This is done by setting the FORCE_LINEBREAK_POLICY exporter parameter to true, or by setting the net.sf.jasperreports.export.pdf.force.linebreak.policy property to true either globally (in jasperreports.property) or at report level.


    User Feedback

    Recommended Comments

    Thank you, I spent far too long trying to figure out what was wrong with my pdf. Every time I saved the publisher file as a pdf it would cut off ONLY the 1st part of the 1st letter of the 1st line.

    Switched to a similar font, NO issue.

    Thank you again!

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