0

I am trying to create an image and put japanese text on it . It works fine in local. but when I upload and deploy my project in amazone web service ec2 , the japanese text displays squares in the image . (I am using wildfly 9 as server )

Image created :

enter image description here

my code is below :

void CreateImage(String topic, String name, String id, boolean candidate,int idvideo) {
    try {



        BufferedImage bufferedImage = ImageIO
                .read(new File(ImagePath));

        Graphics graphics = bufferedImage.getGraphics();
        String  myString="承認待ち he new guy ट्रेल्स   " ;
        graphics.setColor(Color.BLACK);
        byte ptext[] = myString.getBytes("UTF-8");
        String value;
        value = new String(ptext, "UTF-8");
        graphics.setFont(new Font("Arial", Font.PLAIN, 10));

        graphics.drawString(value, 10, 90);
            if (id != null && !id.equals("")) {
            graphics.drawString("大学で学んだこと", 0, 100);
        }

        if (candidate) {
            ImageIO.write(bufferedImage, "png",
                    new File( path1));
        } else {
            ImageIO.write(bufferedImage, "png",
                    new File(path2));

        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}
nejm
  • 1
  • 3
  • did you saved .java file with Unicode ? – Mohsen_Fatemi Jan 04 '17 at 16:34
  • or it is ansi ? – Mohsen_Fatemi Jan 04 '17 at 16:35
  • Pretty sure `graphics.setFont(Font.getFont(""));` is a guaranteed failure on "not your computer". Why would Amazon have a default font for Japanese set up? Or almost any other language that doesn't match its server region, really. – Mike 'Pomax' Kamermans Jan 04 '17 at 16:36
  • Seems like your server doesn't have fonts with Japanese characters. Try to find and install appropriate font as described [here](http://askubuntu.com/questions/234520/does-ubuntu-provide-extra-fonts-through-a-font-package). – Maxim Jan 04 '17 at 16:36
  • if you are using javac use this command : `javac -encoding UTF-8` – Mohsen_Fatemi Jan 04 '17 at 16:37
  • I think this question has a duplicate one : [click here](http://stackoverflow.com/questions/4067628/how-to-use-chinese-and-japanese-character-as-string-in-java) – Mohsen_Fatemi Jan 04 '17 at 16:39
  • I used also new Font("Arial", Font.PLAIN, 10) ; and i get the same problem .Is Asian font support is available in the Amazon or i should install it ???? – nejm Jan 04 '17 at 16:59
  • 1) Better to post a [mcve]. 2) `new Font("Arial", Font.PLAIN, 10)` This is very fragile in that it presumes Arial font is installed. 3) Use [`Font.canDisplayUpTo(String)`](http://docs.oracle.com/javase/8/docs/api/java/awt/Font.html#canDisplayUpTo-java.lang.String-) to discover which fonts can display a given string. – Andrew Thompson Jan 05 '17 at 16:24

1 Answers1

0

I solved it by installing Japanese support in the AWS server . As well as not supporting any Asian characters out the box, it doesn't have them in any of its Amazon repositories.I did manage to register the centos repository for yum on the box, so we could install packs from that.

sudo yum groupinstall "Korean Support" "Chinese Support" "Japanese Support"

nejm
  • 1
  • 3