2013-07-01 77 views
3

我正在使用iText v5 in ColdFusion 9並希望包含CopyRight符號。文檔和書籍說通過unicode字符串,例如\u00a9。我回來的是字符串,而不是符號。這是我的測試用例:iText v5 unicode和ColdFusion

// 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); 

這就是輸出(拷貝FOM的PDF):

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

通知的已註冊和版權符號正確地顯示在版本字符串所以字體可顯示他們。

我想我錯過了一些真正基本的東西,但不能看到它。我知道我並不需要創建自己的java.lang.String,因爲這正是CF所做的,但是爲了消除這種可能性,我走了那麼遠。

+0

會發生什麼,如果你只是做'海峽=的CreateObject( 「Java」 的, 「java.lang.String中」)的init( 'Acme的Products®');' – duncan

回答

0

使用chr(169)而不是\ u00a9。 可能如下圖所示。

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

感謝。 !就是這樣。並且,要完成: \t str =「Trademark」&chr(InputBaseN('2122',16)); \t str =「Registered」&chr(InputBaseN('00AE',16)); \t str =「Copyright」&chr(InputBaseN('00A9',16)); – Murrah

2

@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/

穆雷

+0

是的...這也是不錯的選擇。 –