jasper文本字段被截断 [英] jasper text field getting truncated

查看:276
本文介绍了jasper文本字段被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jasper报告出现了字体问题,其中一个较为冗长的文本字段(详细信息区中的最后一个字段)在PDF和PDF预览中被截断,而在内部预览中则没有。

I'm having a font issue with my jasper report where one of my more wordy text fields (the last one in a detail band) is getting cut off in the PDF and PDF Preview but not in the Internal Preview.

例如。

内部预览:

Here is a fake description. It fits
perfectly, fitting just in the lines.

PDF预览

Here is a fake description. It 
fits perfectly, fitting just in the

Jasper(看似)使用一些算法来弄清楚这个字段应该有多高,我的文字几乎不合适,然后当生成PDF时,文本会在下一行包装并消失。

Jasper is (seemingly) using some algorithm to figure out how tall the field should be, my text is barely fitting, then when the PDF is generated the text wraps and disappears on the next line.

我不是使用自定义字体(只是默认/隐式SansSerif),而不使用除粗体/斜体之外的任何自定义样式。在iReport的PDF预览版和我在Windows和MacOS上生成的代码中都可以证明这种行为(Linux可能仍有问题,但我的示例文本没有在Ubuntu上显示行为)。

I'm not using custom fonts (just the default/implicit "SansSerif"), and not using any custom styles beyond bold/italic. This behavior is demonstrable in both iReport's PDF Preview and my code's generated PDF on Windows and MacOS (Linux likely still has the issue, but my example text didn't exhibit the behavior on Ubuntu).

我使用Stretch Type,Position Type和Stretch with Overflow,以及将此文本字段移动到自己的乐队但没有修复此错误(其中一些导致其他错误)。

I've played with Stretch Type, Position Type, and Stretch with Overflow, as well as moved this text field to its own band but none fixes this bug (and several of them cause others).

我很幸运地将字体更改为其他内置字体,但这只是告诉我我的示例不适用于该特定字体,而不是我修复了错误。

I've had luck changing the font to the other built-in fonts, but this just tells me my example doesn't work for that particular font, not that I've fixed the bug.

我们非常感谢任何提示。

Any tips would be greatly appreciated.

更新1

我尝试从Jasper Reports 5.2.0升级到6.2.0,将Jasper Fonts 4.0.0升级到6.0.0 ......没有变化。

I tried upgrading from Jasper Reports 5.2.0 to 6.2.0 and Jasper Fonts 4.0.0 to 6.0.0... no change.

更新2

尝试编辑我的 src / main / resources / jasperreports_extension.properties 并添加

net.sf.jasperreports.export.pdf.force.linebreak.policy=true

...没有变化。

(值得注意的是,虽然在我的用例中我不能使用 isStretchWithOverflow =true,所以这可能就是为什么它不起作用。)

(Notably though in my use-case I can't use isStretchWithOverflow="true", so this may be why it didn't work.)

更新3

我尝试通过编辑 src / main / resources / jasperreports_extension.xml 并添加:

I tried embedding the font by editing src/main/resources/jasperreports_extension.xml and adding:

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.arialFontFamily=fonts/customFontFamilies.xml

customFontFamilies.xml:

customFontFamilies.xml:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
 <fontFamily name="ArialEM">
   <normal><![CDATA[fonts/Arial/Arial.ttf]]></normal>
   <bold><![CDATA[fonts/Arial/Arial Bold.ttf]]></bold>
   <italic><![CDATA[fonts/Arial/Arial Italic.ttf]]></italic>
   <boldItalic><![CDATA[fonts/Arial/Arial Bold Italic.ttf]]>/boldItalic>
   <pdfEncoding><![CDATA[Cp1252]]></pdfEncoding>
   <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
 </fontFamily>
</fontFamilies>

...没有骰子。 (虽然这确实有助于解决Firefox的PDF渲染器无法渲染粗体字体的问题。)

... no dice. (Though this did help with an issue where Firefox's PDF renderer wouldn't render bold fonts.)

更新4

我注意到在所有测试用例中我都能创建第一行为空白,因此我将特定单元格更改为 vertical-align top ,哪个有效,但当然当一个单元格没有太多文本时就会错位。

I noticed that in all the test-cases I was able to create that the first line was blank, so I changed the particular cell to be vertical-align top, which worked, but of course made that one cell misalign when there wasn't much text in it.

将其作为解决方案废弃,但可能适用于某人。

Scrapped that as a solution, but may work for someone.

更新5

此时希望很明显我已尝试过真实 解决方案并看着他们都死于可怕的死亡。因此,我们进入了黑客解决方案的领域。首先我尝试了@ wmmci的解决方案,但他的回答改变了我的盒子的高度(由于它是由动态Jasper 动态计算的)。我注意到我可以创建的所有示例都涉及字符串中的字内句点,例如富......吧。这可能不是你的情况,但它适合我。所以我在字内空格后注入了头发空间(&#8202; )。

At this point hopefully it's clear I've tried the "real" solutions and watched them all die a horrible death. Thus, we enter the realm of the hack solution. First I tried @wmmci's solution, but his answer changes the height of my box (due to it being dynamically calculated by Dynamic Jasper). I noticed that all of the examples I could create involved intra-word periods in the string, e.g. "foo...bar". That might not be your case, but it was for me. So I injected a "hair space" (&#8202;) after intra-word spaces.

这显然不是一个真正的解决方案,只是一个临时的解决方案,直到我能找到更多的bug例子。

This is obviously not a real solution, just a temporary work-around until I'm able to find more examples of the bug.

更新6

我查了一下,我没有@KarolisŠarapnickis与的问题printOrder 。呃,好吧。我会继续战斗。 ; - )

I checked and I don't have @KarolisŠarapnickis's issue with the printOrder. Ah well. I shall soldier on. ;-)

推荐答案

我有同样的问题,我尝试了所有可能的配置 - 没有用。最后,作为一种解决方法,我在字段中附加了一个新的行字符并且它有效。
如下:$ F {description} +\ n

I had same issue and I tried all possible configurations - didn't work. Finally as a workaround I appended a new line character to the field and it worked. Something like this: $F{description} + "\n"

这篇关于jasper文本字段被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆