【问题标题】:iText v5 unicode and ColdFusioniText v5 unicode 和 ColdFusion
【发布时间】:2013-07-01 03:25:58
【问题描述】:

我在 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®');

标签: unicode coldfusion itext


【解决方案1】:

@Pritesh 帕特尔

谢谢!就是这样。而且,对于 unicode 来说是完整的(因为我也想要商标):

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

换句话说,CHR() 也处理 unicode。代码可在此处获得:http://www.unicode.org/

穆雷

【讨论】:

    【解决方案2】:

    使用 chr(169) 代替 \u00a9。 可能如下所示。

    str = CreateObject("java","java.lang.String").init('Acme Products#chr(169)#');
    

    【讨论】:

    • 谢谢!就是这样。并且,要完整: str = "Trademark" & chr( InputBaseN( '2122', 16 ) ); str = "已注册" & chr( InputBaseN( '00AE', 16 ) ); str = "版权" & chr( InputBaseN( '00A9', 16 ) );
    猜你喜欢
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    相关资源
    最近更新 更多