Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4822274

DocPrintJob.print method locates incorrect printer from a set

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0, 1.4.1
    • client-libs
    • 2d
    • x86
    • linux, solaris



      Name: jk109818 Date: 02/21/2003


      FULL PRODUCT VERSION :
      On the Linux machine, the version of Java is:
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

      On the Sparc machine, the version is:
      java version "1.4.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
      Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)


      FULL OPERATING SYSTEM VERSION :
      The problem is observed on Linux and on Sparc/Solaris
      I tested it under
      Red Hat Linux release 7.0 (Guinness)
      and
      Solaris 8 10/00 s28s_u2wos_11b SPARC

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      We have many PostScript printers on our local area network.
      They are accessed by IP address.

      A DESCRIPTION OF THE PROBLEM :
      In an environment where there are several PostScript
      printers, only the first printer reported by the
      PrintServiceLookup.lookupPrintServices method can be
      accessed with the DocPrintJob.print method.

      If the DocPrintJob object is created from any other
      PrintService object in the array, the PrintJob will still go
      to the first one in the list.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Find an environment where more than one PostScript
      printer is on the local network.
      2. Compile and run the example program that I have provided.
      3. Look at the queues for the first and the second printer
      in the list printed by the example program. Walk to the
      first printer in the list and get the single page output,
      even though it should have printed on the second printer.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      When I run the program in my environment, the list of
      printers is printed as:
      laser104g
      laser104d
      ...

      The program is requesting the page to be printed on
      laser104d. It will instead be printed on laser104g.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.print.DocFlavor;
      import javax.print.PrintService;
      import javax.print.attribute.PrintRequestAttributeSet;
      import javax.print.attribute.HashPrintRequestAttributeSet;
      import javax.print.attribute.standard.Copies;
      import javax.print.attribute.standard.MediaSize;
      import javax.print.attribute.standard.Sides;
      import javax.print.Doc;
      import javax.print.SimpleDoc;
      import javax.print.DocPrintJob;
      import javax.print.PrintServiceLookup;
      import javax.print.PrintException;
      import java.io.ByteArrayInputStream;

      public class PrintEx3
      {
         String ps = "%!\n"+
            "30 30 moveto 565 30 lineto 565 812 lineto 30 812 lineto closepath\n"+
            "565 30 moveto 30 812 lineto .5 setgray stroke 0 setgray\n"+
            "/Times-Bold findfont 20 scalefont setfont\n"+
            "60 782 moveto (Big bold heading at top of page) show\n"+
            "/Times-Roman findfont 15 scalefont setfont\n"+
            "60 700 moveto (We can print any PostScript file from Java now !)show\n"+
            "showpage\n";
            
         public static void main(String s[])
         {
            PrintEx3 pe = new PrintEx3();
         }

         public PrintEx3()
         {
               DocFlavor psInFormat = DocFlavor.BYTE_ARRAY.POSTSCRIPT;
               Doc myDoc = new SimpleDoc(ps.getBytes(), psInFormat, null);
               PrintService[] services =
                  PrintServiceLookup.lookupPrintServices(psInFormat, null);
               for (int i=0; i<services.length; ++i)
                  System.out.println(services[i].getName());
               if (services.length > 1)
               {
                  DocPrintJob job = services[1].createPrintJob();
                  try { job.print(myDoc, null); }
                  catch (PrintException ex) { ex.printStackTrace(); }
               }
         }
         
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      None. Only the first printer found can be accessed.
      (Review ID: 178695)
      ======================================================================

            jgodinez Jennifer Godinez (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: