iText v5 Unicode 和 ColdFusion

3

我正在使用 ColdFusion 9 中的 iText v5,并想要包含版权符号CopyRight。文档和书籍上说要传递unicode字符串,例如\u00a9。但我得到的是这个字符串,而不是符号。以下是我的测试案例:

// Ask iText what version it is. This include the Registered and Copyright symbols so this
// font can obviously display them
vers = variables.javaLoader.create("com.itextpdf.text.Version").getVersion();

// Make a new paragraph and add the version number to the document
vPara = variables.javaLoader.create("com.itextpdf.text.Paragraph").init(vers);
myDoc1.add(vPara);

// Make a new string including the CopyRight symbol as per the iText docs and book
str = CreateObject("java","java.lang.String").init('Acme Products\u00a9');

// Make another paragraph and add the string to the document 
para = variables.javaLoader.create("com.itextpdf.text.Paragraph").init(str);
myDoc1.add(para);

以下是输出结果(从pdf中复制):

iText® 5.4.1 ©2000-2012 1T3XT BVBA
Acme Products\u00a9 

请注意,注册商标和版权符号在版本字符串中正确显示,因此字体可以显示它们。

我认为我可能缺少一些基本的东西,但是看不到。我知道我实际上不需要创建自己的java.lang.String,因为这正是CF所做的,但只是为了消除这种可能性,我走得那么远。


如果您只执行 str = CreateObject("java","java.lang.String").init('Acme Products®');,会发生什么? - duncan
2个回答

2

@Pritesh Patel

谢谢!就是这样。为了完整起见(因为我也想要商标):

str = "Trademark"  & chr( InputBaseN( '2122', 16 ) );
str = "Registered" & chr( InputBaseN( '00AE', 16 ) );
str = "Copyright"  & chr( InputBaseN( '00A9', 16 ) );

换句话说,CHR()也处理Unicode。这里提供了代码:http://www.unicode.org/
Murray

0
使用 chr(169) 代替 \u00a9。 可能看起来像下面这样。
str = CreateObject("java","java.lang.String").init('Acme Products#chr(169)#');

谢谢!就是这样。为了完整起见:str = "商标" & chr(InputBaseN('2122',16)); str = "注册" & chr(InputBaseN('00AE',16)); str = "版权" & chr(InputBaseN('00A9',16)); - Murrah

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接