生成的 pdf 文件中的文本换行问题
我有一个与 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,使用字体扩展。您的问题很可能是因为 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
您可以通过在文本末尾添加空格来避免这种情况。我也在使用 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.
某些元素(TextField 或 StaticText)可以根据
拉伸类型
和溢出拉伸
属性来增加其高度。但元素的宽度不能在不编程的情况下改变。引自
iReport Ultimate Guide
:您可以使用,例如 ColumnBuilder< /a> 来自 DynamicJasper API 的类来设置列 宽度。
您还可以阅读此讨论。
Some elements (TextField or StaticText) can increase its height depends on
stretch type
andstretch with overflow
properties. But element's width can not be changed without programming.The quote from
iReport Ultimate Guide
:You can use, for example ColumnBuilder class from DynamicJasper API to set column width.
You can also read this discussion.
对于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.