2 Replies Latest reply on Apr 18, 2011 5:04 AM by 855532

    Problem in printing Chinese characters by using JavaPrintService

      Hi, I just develop a tool to print txt files by using Java Print Service.

      Everything seems to be good, but when the file contains Chinese character, it can't be print correctly.

      I tried to use the DocFlavor.Reader and DocFlavor.STRING, however all of them are failed.

      My code is below, please help me, thanks so much

      PrintRequestAttributeSet pars = new HashPrintRequestAttributeSet();
      // TODO:Printing is not correct because of the Chinese Encoding
      DocFlavor flavor = new DocFlavor.INPUT_STREAM("text/plain;charset=UTF-8");//DocFlavor.INPUT_STREAM.AUTOSENSE;

      PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
      if(defaultService != null){
      Iterator<String> it = filename.iterator();
      shortname = it.next().toString();
      abstractPath = GlobalVar.SRC_DIRECTORY_PATH + shortname;
      File file = new File(abstractPath);
      DocPrintJob job = defaultService.createPrintJob();
      FileInputStream fis = new FileInputStream(file);
      //BufferedReader br = new BufferedReader(new InputStreamReader(fis,"UTF-8"));
      DocAttributeSet das = new HashDocAttributeSet();
      Doc doc = new SimpleDoc(fis,flavor,das);
      job.print(doc, pars);
      }catch(PrintException ex){
      Log.doLog("Print failed\t" + shortname, Log.ERROR);
      Log.doLog("File can't be found: "+abstractPath, Log.ERROR);
      Log.doLog("Can't find printer", Log.ERROR);