8 Replies Latest reply: Jan 8, 2009 5:45 AM by 807589 RSS

    Problem in displaying the Japanese character

    807589
      Hi

      Im trying to display the Japanese characters in pdf report(Using iText Report). I have the method as follows which is encoding the characters in a particular format in my say, Reports.java

      public String stringFormat( String strData ) throws Exception {

      String result=null;
      try{
      result = new String(strData.toString().getBytes("Shift-JIS"),"UTF-8");

      }catch(Exception e) {}
      return result;
      }

      Im calling this method to display a category code in another one java file like

      Phrase colm_2 = new Phrase(report.stringFormat(strCatgdes),font);

      But Im nt getting the correct japanese chars, instead im seeing like this ??????? in my pdf report. I tried with different encoding char set like "ISO2022JP,EUC_JP,SJIS,Shift-JIS,MS932,Cp33722". All giving the wrong characters.

      Can anyone help me to solve this issue?

      Thanks in Advance.
        • 1. Re: Problem in displaying the Japanese character
          807589
          I would think that this statement,
          result = new String(strData.toString().getBytes("Shift-JIS"),"UTF-8");
          says to convert "strData" into bytes using the Shift_JIS charater encoding. Once in byte format, it's not like UTF-8 will understand it since it was encoded with something else. Thus when you create a new string object and say "use UTF-8 to decode the bytes" you end up getting garbage.
          • 2. Re: Problem in displaying the Japanese character
            807589
            Could you tell any solution for this issue?
            • 3. Re: Problem in displaying the Japanese character
              807589
              Your solution would be to completely get rid of that stringFormat(...) method entirely. There is no meaning to it. Eigther you work with a java String object, or you work with the encoded bytes. To encode a string into bytes and decode it into the same String seems pointless.

              A java String object is perfectly capable of displaying every unicode character in existence. This includes the complete set of japanese characters. That is, instead of doing
              Phrase colm_2 = new Phrase(report.stringFormat(strCatgdes),font);
              what happens if you do,
              Phrase colm_2 = new Phrase(strCatgdes,font);
              Edited by: Maxideon on Dec 30, 2008 10:41 PM
              Wait a minute... Are you trying to identify the japanese characters in "strCatgdes"?
              • 4. Re: Problem in displaying the Japanese character
                807589
                Hi

                Im getting from the table by using this below result set.

                strCatgdes     = rs.getString("CC_DES");

                While viewing the data, Im seeing the correct Japanese chars. But displaying in the PDF only its giving like this "?????" characters.
                • 5. Re: Problem in displaying the Japanese character
                  807589
                  Hi,

                  as the others said, there is no needing to convert the String into another encoding. Strings in Java are all already in Unicode. You have to use a Font that has glyphs for the japanese chars. With this Font you have to work in for example
                   new Paragraph(String string, Font font)
                  or
                   new Phrase(String string, Font font)
                  See [http://itextdocs.lowagie.com/tutorial/fonts/getting/index.php] for examples.

                  best regards

                  Axel
                  • 6. Re: Problem in displaying the Japanese character
                    807589
                    Hi Axel,

                    At present Im using the iText-2.0.1.jar only. Do I need to use both iTextAsian.jar and iTextAsianCmap.jar?

                    Thanks & Regards

                    Dhilip
                    • 7. Re: Problem in displaying the Japanese character
                      807589
                      Hi,
                      dhilip wrote:
                      Do I need to use both iTextAsian.jar and iTextAsianCmap.jar?
                      I don't know. I don't use CJK but other fonts. But I've googled for you and found a concrete example:
                      [http://www.1t3xt.info/examples/browse/?page=example&id=142]
                      Seems only iText.jar and iTextAsian.jar needed. The iTextAsianCmaps.jar contains additional CharMaps, it seems.

                      best regards

                      Axel
                      • 8. Re: Problem in displaying the Japanese character
                        807589
                        Hi Axel

                        Still I have the problem in displaying the Japanese characters in pdf.

                        This is my code

                        BaseFont bf = BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H",BaseFont.EMBEDDED);
                        Font font1 = new Font(bf, 9);

                        Phrase colm_2          = new Phrase(strCatgdes,font1);

                        I tried with different japanese fonts like HeiseiMin-W3, HeiseiKakuGo-W5 and KozMinPro-Regular with the encodings UniJIS-UCS2-H, UniJIS-UCS2-HW-H

                        Actual "strCatgdes" value is 日本語. But its displaying like this "æ��¥æ��¬èª��" in pdf.

                        Could you please tell me the suggestion, if you know?

                        Thanks in Advance

                        Dhilip