PrintServiceLookup to locate print
services that have the capabilities to satisfy the application's print
request. For example, to print a double-sided document, the application first
needs to find printers that have the double-sided printing capability.
The JDK includes PrintServiceLookup implementations that can locate
the standard platform printers. To locate other types of printers, such as
IPP printers or JINI printers, a print-service provider can write
implementations of PrintServiceLookup. The print-service provider can
dynamically install these PrintServiceLookup implementations using
the java. facility.
javax.print.attribute and javax.print.attribute.standard
packages define print attributes, which describe the capabilities of a print
service, specify the requirements of a print job, and track the progress of a
print job.
The javax.print.attribute package describes the types of attributes
and how they can be collected into sets. The
javax.print.attribute.standard package enumerates all of the standard
attributes supported by the API, most of which are implementations of
attributes specified in the IETF Specification,
RFC 2911 Internet Printing
Protocol, 1.1: Model and Semantics, dated September 2000. The attributes
specified in javax.print.attribute.standard include common
capabilities, such as: resolution, copies, media sizes, job priority, and
page ranges.
DocFlavor class represents the print data
format, such as JPEG or PostScript. A DocFlavor object consists of a
MIME type, which describes the format, and a document representation class
name that indicates how the document is delivered to the printer or output
stream. An application uses the DocFlavor and an attribute set to
find printers that can print the document type specified by the
DocFlavor and have the capabilities specified by the attribute set.
DocFlavor.
DocFlavor and the attribute set.
Doc object encapsulating the
DocFlavor and the actual print data, which can take many forms
including: a Postscript file, a JPEG image, a URL, or plain text.
DocPrintJob, from the print service.
FileInputStream psStream; try { psStream = new FileInputStream("file.ps"); } catch (FileNotFoundException ffne) { } if (psStream == null) { return; } DocFlavor psInFormat = DocFlavor.INPUT_STREAM.POSTSCRIPT; Doc myDoc = new SimpleDoc(psStream, psInFormat, null); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(5)); aset.add(MediaSizeName.ISO_A4); aset.add(Sides.DUPLEX); PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset); if (services.length > 0) { DocPrintJob job = services[0].createPrintJob(); try { job.print(myDoc, aset); } catch (PrintException pe) {} }
Note
In the javax.print APIs, a null reference
parameter to methods is incorrect unless explicitly documented on the method
as having a meaningful interpretation. Usage to the contrary is incorrect
coding and may result in a run time exception either immediately or at some
later time. IllegalArgumentException and NullPointerException
are examples of typical and acceptable run time exceptions for such cases.
| Modifier and Type | Interface and Description |
|---|---|
| public interface | AttributeException
Interface |
| public interface | CancelablePrintJob
This interface is used by a printing application to cancel a print job. |
| public interface | Doc
Interface |
| public interface | DocPrintJob
This interface represents a print job that can print a specified document with a set of job attributes. |
| public interface | FlavorException
Interface |
| public interface | MultiDoc
Interface |
| public interface | MultiDocPrintJob
Obtained from a |
| public interface | MultiDocPrintService
Interface |
| public interface | PrintService
Interface |
| public interface | URIException
Interface |
| Modifier and Type | Class and Description |
|---|---|
| public class | DocFlavor
Class |
| pack-priv class | |
| public class | PrintException
Class |
| public abstract class | PrintServiceLookup
Implementations of this class provide lookup services for print services (typically equivalent to printers) of a particular type. |
| public class | ServiceUI
This class is a collection of UI convenience methods which provide a graphical user dialog for browsing print services looked up through the Java Print Service API. |
| public abstract class | ServiceUIFactory
Services may optionally provide UIs which allow different styles of interaction in different roles. |
| public class | SimpleDoc
This class is an implementation of interface |
| public abstract class | StreamPrintService
This class extends |
| public abstract class | StreamPrintServiceFactory
A |