简体   繁体   English

itext5:非英语断字不起作用

[英]itext5: non-English hyphenation not working

I'm generating a PDF in java using itext5.我正在使用 itext5 在 java 中生成 PDF。 Hyphenation works fine when I use an 'en' HyphenationAuto object.当我使用“en” HyphenationAuto 对象时,连字符工作正常。 The xml jar is on the class path. xml jar 位于类路径上。 In the debugger, the objects are non-null.在调试器中,对象是非空的。

When I switch to use 'qq' as the language (a nonsense code), the hyphenation object in the debugger is null, as expected, because the xml jar for hyphenation has no file named qq.xml.当我切换到使用“qq”作为语言(无意义代码)时,调试器中的连字符对象为空,正如预期的那样,因为连字符的 xml jar 没有名为 qq.xml 的文件。

But when I use French-hyphenation instead of English-hyphenation, it fails to hyphenate at all.但是当我使用法语连字符而不是英语连字符时,它根本无法连字符。

When I switch to use 'fr' as the language, the hyphenation object in the debugger is non-null , as expected, showing that at least it's reading the xml file from the underlying jar.当我切换到使用 'fr' 作为语言时,调试器中的断字对象是非 null ,正如预期的那样,表明至少它正在从底层 jar 读取 xml 文件。 BUT the hyphenation is not occurring in the output PDF.但是在输出 PDF 中没有出现断字。

This would indicate a problem with the input text data, but I can't see any issues.这表明输入文本数据有问题,但我看不出任何问题。 There are no non-breaking spaces in the text data.文本数据中没有不间断空格。

Changing my JRE's default locale has no effect.更改我的 JRE 的默认语言环境无效。

When I use the 'en' hyphenator with French text, there are hyphens at line breaks, but the wrong rules are being applied (and it shows).当我在法语文本中使用“en”连字符时,在换行符处有连字符,但应用了错误的规则(并显示)。 That indicates no fundamental issue with the French text.这表明法文文本没有根本问题。

The core itext code is simply:核心itext代码很简单:

private static final HyphenationEvent hyphen = new HyphenationAuto("en", "GB", 2, 2);
//...
Paragraph para = new Paragraph();
para.setAlignment(Element.ALIGN_JUSTIFIED); 
para.setHyphenation(hyphen);
Chunk chunk = new Chunk(paragraphText);
para.add(chunk);
doc.add(para);

The fix for me was to get a fresher version of the jar.对我来说,解决方法是获得更新版本的 jar。

I upgraded from 5.1.0 to 5.1.1.我从 5.1.0 升级到 5.1.1。

I downloaded the 5.1.1 jar from here .我从这里下载了 5.1.1 jar。

Perhaps I had a corrupt version of the 5.1.0 jar.也许我有一个损坏的 5.1.0 jar 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM