1 Reply Latest reply: Sep 8, 2009 9:44 PM by 796365 RSS

    Printing issue using DocFlavor.INPUT_STREAM.AUTOSENSE

    807580
      Really really need some help,

      I’m trying to print a PostScript file. This code works, it prints the PostScript file but only creates 1 copy, it's ignoring the PrintRequestAttributeSet.
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
      aset.add(new Copies(2));
                  
      PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
      DocPrintJob job = printService.createPrintJob();
                  
      FileInputStream fis = new FileInputStream("test.ps");
      SimpleDoc simpleDoc = new SimpleDoc(fis,DocFlavor.INPUT_STREAM.AUTOSENSE, null);
                  
      job.print(simpleDoc, aset);
      If I use DocFlavor.INPUT_STREAM.POSTSCRIPT to print the PostScript file I get an exception:

      "sun.print.PrintJobFlavorException: invalid flavor"

      So I tried to print a GIF image. This code gives me the correct 2 copies.
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
      aset.add(new Copies(2));
                  
      PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
      DocPrintJob job = printService.createPrintJob();
                  
      FileInputStream fis = new FileInputStream("test.gif");
      SimpleDoc simpleDoc = new SimpleDoc(fis,DocFlavor.INPUT_STREAM.GIF, null);
                  
      job.print(simpleDoc, aset);
      This code uses DocFlavor.INPUT_STREAM.AUTOSENSE and only gives me the 1 copy, it's ignoring the PrintRequestAttributeSet.
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
      aset.add(new Copies(2));
                  
      PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
      DocPrintJob job = printService.createPrintJob();
                  
      FileInputStream fis = new FileInputStream("test.gif");
      SimpleDoc simpleDoc = new SimpleDoc(fis,DocFlavor.INPUT_STREAM.AUTOSENSE, null);
                  
      job.print(simpleDoc, aset);
      So why does using DocFlavor.INPUT_STREAM.AUTOSENSE cause the printing to ignore the PrintRequestAttributeSet?

      and how do I print the PostScript file and have it use the PrintRequestAttributeSet?

      Thanks
      -d
        • 1. Re: Printing issue using DocFlavor.INPUT_STREAM.AUTOSENSE
          796365
          Printers support only certain doc flavors. This is a printer constraint. You can run this program and it will list printers that Java can use, and the doc flavors that each support.
          import javax.print.DocFlavor;
          import javax.print.PrintService;
          import javax.print.PrintServiceLookup;
          
          public class DocFlavorLister
          {
              public static void main(String args[])
              {
                  PrintService[] allServices =
                      PrintServiceLookup.lookupPrintServices(null, null);
                  for (PrintService ps : allServices)
                  {
                      System.out.println(ps + " supports :");
                      DocFlavor[] flavors = ps.getSupportedDocFlavors();
                      for (int i = 0; i < flavors.length; i++)
                      {
                          System.out.println("\t" + flavors);
          }
          }
          }
          }