tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicholson, Robb" <robb.nichol...@frontiercorp.com>
Subject RE: [Off Topic] Java printing to network printer
Date Fri, 02 Jan 2004 20:29:29 GMT
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:merrill.cornish@earthlink.net]
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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message