生成的 pdf 文件中的文本换行问题

发布于 2024-12-13 07:45:55 字数 976 浏览 8 评论 0原文

我有一个与 pdf 格式文本换行相关的问题。对于 xls、rtf 和 pptx 等所有格式,报告都可以正常工作,但是在 pdf 中,某些文本会被换行,即文本的一些字母,尤其是最后几个字母会打印在下一行中。我已经尝试了该文本属性中的几乎所有选项。我可以减少影响的唯一方法是将这些文本的 pdf 字体名称更改为 times roman。然而,即使这在某些情况下也不起作用。

该代码片段包含问题 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>

如果您分享一些解决方案,我将非常感激。 谢谢...

Ps 当我从 Ireport 4.0.2 生成报告时遇到这个问题

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

把时间冻结 2024-12-20 07:45:55

首先,使用字体扩展。您的问题很可能是因为 JasperReports (iText) 没有使用您希望它在生成 PDF 时使用的字体。字体扩展解决了这个问题。

其次,您可能遇到的问题已得到解决。 JasperReports 4.1.1 变更日志包括以下内容:

net.sf.jasperreports.export.pdf.force.linebreak.policy 配置属性现已弃用,因为PDF 文本呈现代码已重构,以便文本呈现方式与 AWT 中完全相同

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

笑红尘 2024-12-20 07:45:55

您可以通过在文本末尾添加空格来避免这种情况。我也在使用 jasper4.0.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.

一个人练习一个人 2024-12-20 07:45:55

某些元素(TextField 或 StaticText)可以根据拉伸类型溢出拉伸属性来增加其高度。但元素的宽度不能在不编程的情况下改变。

引自iReport Ultimate Guide

拉伸类型 - 该属性定义如何计算元素
打印精细过程中的高度;三个可能的值如下
如下:

  • NoStretch - 这是预定义的拉伸类型,它
    规定元素高度应保持相等。
  • RelativeToBandHeight - 元素高度随着带区大小的增加而成比例增加;这对于模拟表格边框的垂直线很有用。
  • RelativeToTallestObject - 元素根据最近元素的变形修改其高度:此选项也与元素组一起使用,这是一种不由 iReport 管理的元素组机制

    拉伸溢出 - 选择此选项后,如果元素不足以包含所有文本行,则此选项允许文本字段垂直适应内容

  • 您可以使用,例如 ColumnBuilder< /a> 来自 DynamicJasper API 的类来设置列 宽度。

    您还可以阅读此讨论

    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.

    等你爱我 2024-12-20 07:45:55

    对于iReport 4.0.2中pdf导出中的文本换行问题

    将字体转换为Jar,然后添加为外部jar,肯定会起作用。

    在iReport设计器中:

    步骤1)工具->选项->字体->安装您的字体

    步骤 2) 选择该字体 ->单击导出为扩展[将其作为JAR]

    步骤3)转到类路径->单击添加 Jar ->添加你的字体 jar ->确定

    现在预览报告。

    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.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文