Getting Unicode

I am using iText to generate a PDF file that will load to my browser. The thing is, I have Japanese characters that I want to show in the PDF file. These Japanese characters are from the database. With iText, I need to get the Unicode of the Japanese strings that I have. I want to have my Japanese string converted to something like this: \u53d6\u6e96\u53d7

Can this be done in code? I know native2ascii exists but I don't know if I can use it in my code.

Thank you.

[487 byte] By [rainagamboaa] at [2007-10-2 15:43:48]
# 1

Hi ,

we can see the japanese text in PDF from database.

can u let me know what is the database charset?

ur PDF will display chinese or japanese only if the

format is UCS-2.

so we need to convert whatever charset in Database to UCS-2 in java before u write it as pdf.

so what is ur database charset?

vijayramaa at 2007-7-13 15:34:23 > top of Java-index,Desktop,I18N...
# 2

I am surprised to hear that iText requires that. I also doubt it, but I don't feel like checking myself so I will just give you some code:char c = // something

String s = "\\u" + Integer.toHexString((int) c);

DrClapa at 2007-7-13 15:34:23 > top of Java-index,Desktop,I18N...
# 3
It's... Shift_JIS. I don't know is that's the right answer. lol
rainagamboaa at 2007-7-13 15:34:23 > top of Java-index,Desktop,I18N...
# 4
Thanks. I need that.The option I'm trying to do now is to convert the Japanese characters to ascii then to hex and add the \u in front. Can someone tell me how to convert to ascii? Thanks.
rainagamboaa at 2007-7-13 15:34:23 > top of Java-index,Desktop,I18N...
# 5

Now I'm sure you're getting bad advice. ASCII can only represent Western letters, digits, and punctuation. You can't convert Japanese characters to ASCII. But they are Unicode characters and you can convert them to Java Unicode escapes, the way I already showed you.

I would be interested to know where you are getting these ideas from.

DrClapa at 2007-7-13 15:34:23 > top of Java-index,Desktop,I18N...
# 6

You need not convert to unicode......use following code to print japanese characters in a pdf. You will also have to download a jar for the same i.e. iTextAsian.jar.

Document document = new Document();

try {

// step 2:

// we create a writer that listens to the document

// and directs a PDF-stream to a file

PdfWriter.getInstance(document,

new FileOutputStream("D:\\deploy\\AOMS.ear\\AOMS.war\\HelloWorld.pdf"));

// step 3: we open the document

document.open();

// step 4: we add a paragraph to the document

/*document.add(new Paragraph("Hello World"));

document.add(new Paragraph(japanese));*/

BaseFont bfJapanese = BaseFont.createFont("HeiseiMin-W3", "UniJIS-UCS2-H", BaseFont.NOT_EMBEDDED);

Font FontJapanese = new Font(bfJapanese, 12, Font.NORMAL);

Paragraph p = new Paragraph(japanese, FontJapanese);

document.add(p);

}

depu20012003a at 2007-7-13 15:34:23 > top of Java-index,Desktop,I18N...