西里尔字母在 Itext 7 中不起作用

问题描述 投票:0回答:1
PdfFont fontrus = PdfFontFactory.createFont(FONTrus, "CP1251", true); 
String a = "\u041e\u0442\u043a\u0443\u0434\u0430 \u0442\u044b?"; 
String b = "Привет мир"; 

Text text = new Text(a);


Text text1 = new Text(b);   
text.setFont(fontrus);
text1.setFont(fontrus); 
Paragraph paragraph = new Paragraph()
                        .add(text).setFontSize(15);
Paragraph paragraph1 = new Paragraph()
                        .add(b).setFontSize(15);

工作-

字符串a =“\u041e\u0442\u043a\u0443\u0434\u0430\u0442\u044b?”;

不工作-

字符串 b = "Привет мир";

enter image description here

在 itext 5 中一切正常,但在 itext7 中不起作用

java itext
1个回答
0
投票

问题绝对不在于您定义字符串变量的方式。事实上,尽管您为文本 B 设置了 setFont(),但在创建新段落时并未使用它。所以:

Paragraph paragraph1 = new Paragraph()
                        .add(b).setFontSize(15);

应该是:

Paragraph paragraph1 = new Paragraph()
                        .add(text1).setFontSize(15);

注意

.add(text1)
add(b)
。 仅通过此修复,这两行都会在 PDF 中输出。

© www.soinside.com 2019 - 2024. All rights reserved.