This discussion is archived
2 Replies Latest reply: Apr 17, 2011 10:04 PM by 855532 RSS

Problem in printing Chinese characters by using JavaPrintService

855532 Newbie
Currently Being Moderated
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 =;
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);


  • Correct Answers - 10 points
  • Helpful Answers - 5 points