0 Replies Latest reply: Apr 19, 2013 1:42 AM by 1004089 RSS

    Unable to print Swedish Character using DocFlavor

    1004089
      Hi All,

      i am trying to print Swedish character using DocFlavor, but its not getting printed.

      My printer only supports below Flavors.

      Win32 Printer : V2PRINTER supports :
      image/gif; class="[B"
      image/gif; class="java.io.InputStream"
      image/gif; class="java.net.URL"
      image/jpeg; class="[B"
      image/jpeg; class="java.io.InputStream"
      image/jpeg; class="java.net.URL"
      image/png; class="[B"
      image/png; class="java.io.InputStream"
      image/png; class="java.net.URL"
      application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
      application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
      application/octet-stream; class="[B"
      application/octet-stream; class="java.net.URL"
      application/octet-stream; class="java.io.InputStream"


      I have tried different encoding format available  like UTF-8, ASCII but i am getting exception Invalid Flavor.
      PFB code snippet.


      package test;

      import java.awt.print.PrinterJob;
      import java.io.FileInputStream;
      import java.io.FileNotFoundException;

      import javax.print.Doc;
      import javax.print.DocFlavor;
      import javax.print.DocPrintJob;
      import javax.print.PrintException;
      import javax.print.PrintService;
      import javax.print.SimpleDoc;
      import javax.print.attribute.HashPrintRequestAttributeSet;
      import javax.print.attribute.PrintRequestAttributeSet;

      public class TestPrinter {

           /**
            * @param args
            */
           public static void main(String[] args)
           {
                String receiptName = "D:\\Receipt.txt";
                
                // retrieve all the printers
                PrintService[] printers = PrinterJob.lookupPrintServices();
                
                // print service declaration
                PrintService printer = null;

                for (int i = 0; i < printers.length; i++)
                {
                     System.out.println(printers.getName());
                     if (printers[i].getName().equalsIgnoreCase("Ricoh Aficio MP 2550B PCL"))
                     {
                          printer = printers[i];
                          System.out.println("Printer Found :" + printers[i].getName());
                     }
                }
                
                FileInputStream psStream = null;
                try
                {
                     psStream = new FileInputStream(receiptName);
                }
                catch (FileNotFoundException e1)
                {
                     // TODO Auto-generated catch block
                     e1.printStackTrace();
                }
      // DocFlavor psInFormat = DocFlavor.BYTE_ARRAY.GIF;
      DocFlavor psInFormat = null;
      // psInFormat = new DocFlavor("text/plain; charset=utf-8", "java.io.InputStream");
      psInFormat = new DocFlavor("text/plain; charset=us-ascii", "java.io.InputStream");
      Doc myDoc = new SimpleDoc(psStream, psInFormat, null);
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                try
                {
                     DocPrintJob job = printer.createPrintJob();
                     job.print(myDoc, aset);
                     psStream.close();
                }
                
                catch (PrintException pe)
                {
                     System.out.println(pe.getMessage());
                }
                catch (Exception e)
                {
                     System.out.println(e.getMessage());
                }
           }
      }




      Please let me know what wrong i am doing here.

      Edited by: user8003374 on Apr 18, 2013 11:40 PM

      Edited by: user8003374 on Apr 18, 2013 11:41 PM