Use the Java Print Services API in JDK 1.4 ( javax.print.* -
http://java.sun.com/j2se/1.4.2/docs/api/javax/print/package-summary.html)

Based on the "DocFlavor" and set of attributes (double sided, 2 up, etc.)
you specify, you can lookup the available print services that can handle
that print job. 

Here's a chunk of code I wrote when learning to use the JPS API. This is the
part that loooks up the available print services and either picks the
default (if defined) or the first in the list. Not very sophisticated, but
you can use something like this to see what printers can be "seen" from your
Java code and what formats the chosen printer supports.

  public PrintService getPrintService(DocFlavor flava,
PrintRequestAttributeSet pSet )
  {
      PrintService[] prnSvcs;
      PrintService prnSvc = PrintServiceLookup.lookupDefaultPrintService();
      
      if (prnSvc != null)
      {
          log.debug("Default Printer found: ["+prnSvc.getName()+"]");
      }
      else
      {
          prnSvcs = PrintServiceLookup.lookupPrintServices(flava, pSet);
          
          if (prnSvcs.length > 0)
          {
              int ii = 0;
              while ( ii < prnSvcs.length )
              {
                  log.debug("Printer found: ["+prnSvcs[ii].getName()+"]");
                  ii++;
              }
              //choose first one for now, eh?
              prnSvc = prnSvcs[0];
          }
      }
      
      // Print out flavors for this selected printer
      DocFlavor[] flavors = prnSvc.getSupportedDocFlavors();
      for (int i = 0; i < flavors.length; i++)
      {
          log.debug("\t[ " + flavors[i].getMimeType() + " | " +
          flavors[i].getRepresentationClassName() +" | "+
          flavors[i].toString()+" ]");
      }
      
      return prnSvc;
  }


-----Original Message-----
From: Merrill Cornish [mailto:[EMAIL PROTECTED]
Sent: Friday, January 02, 2004 3:06 PM
To: Tomcat Users List
Subject: [Off Topic] Java printing to network printer


I apologize for the off-topic question, but can someone point me to 
where I can find out how to print to a remote printer on the LAN from 
Java. 

While Java seems to have many "printing" classes, none of them appear to 
actually reference a physical printer.  While that's obviously in 
keeping with the hardware-independent nature of Java, sometimes an 
application needs to route output to a specific location on the net.  
But how?

Merrill

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to