public interface PrintService
Example:
DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
PrintService[] pservices =
PrintServiceLookup.lookupPrintServices(flavor, aset);
if (pservices.length > 0) {
DocPrintJob pj = pservices[0].createPrintJob();
try {
FileInputStream fis = new FileInputStream("test.ps");
Doc doc = new SimpleDoc(fis, flavor, null);
pj.print(doc, aset);
} catch (FileNotFoundException fe) {
} catch (PrintException e) {
}
}
Modifier and Type | Method and Description |
---|---|
void |
addPrintServiceAttributeListener(PrintServiceAttributeListener listener)
Registers a listener for events on this PrintService.
|
DocPrintJob |
createPrintJob()
Creates and returns a PrintJob capable of handling data from
any of the supported document flavors.
|
boolean |
equals(Object obj)
Determines if two services are referring to the same underlying
service.
|
<T extends PrintServiceAttribute> |
getAttribute(Class<T> category)
Gets the value of the single specified service attribute.
|
PrintServiceAttributeSet |
getAttributes()
Obtains this print service's set of printer description attributes
giving this Print Service's status.
|
Object |
getDefaultAttributeValue(Class<? extends Attribute> category)
Determines this print service's default printing attribute value in
the given category.
|
String |
getName()
Returns a String name for this print service which may be used
by applications to request a particular print service.
|
ServiceUIFactory |
getServiceUIFactory()
Returns a factory for UI components which allow users to interact
with the service in various roles.
|
Class<?>[] |
getSupportedAttributeCategories()
Determines the printing attribute categories a client can specify
when setting up a job for this print service.
|
Object |
getSupportedAttributeValues(Class<? extends Attribute> category,
DocFlavor flavor,
AttributeSet attributes)
Determines the printing attribute values a client can specify in
the given category when setting up a job for this print service.
|
DocFlavor[] |
getSupportedDocFlavors()
Determines the print data formats a client can specify when setting
up a job for this
PrintService . |
AttributeSet |
getUnsupportedAttributes(DocFlavor flavor,
AttributeSet attributes)
Identifies the attributes that are unsupported for a print request
in the context of a particular DocFlavor.
|
int |
hashCode()
This method should be implemented consistently with
equals(Object) . |
boolean |
isAttributeCategorySupported(Class<? extends Attribute> category)
Determines whether a client can specify the given printing
attribute category when setting up a job for this print service.
|
boolean |
isAttributeValueSupported(Attribute attrval,
DocFlavor flavor,
AttributeSet attributes)
Determines whether a client can specify the given printing
attribute
value when setting up a job for this Print Service.
|
boolean |
isDocFlavorSupported(DocFlavor flavor)
Determines if this print service supports a specific
DocFlavor . |
void |
removePrintServiceAttributeListener(PrintServiceAttributeListener listener)
Removes the print-service listener from this print service.
|
String getName()
PrinterName
attribute.DocPrintJob createPrintJob()
void addPrintServiceAttributeListener(PrintServiceAttributeListener listener)
listener
- a PrintServiceAttributeListener, which
monitors the status of a print serviceremovePrintServiceAttributeListener(javax.print.event.PrintServiceAttributeListener)
void removePrintServiceAttributeListener(PrintServiceAttributeListener listener)
PrintService
events.listener
- a PrintServiceAttributeListener objectaddPrintServiceAttributeListener(javax.print.event.PrintServiceAttributeListener)
PrintServiceAttributeSet getAttributes()
getAttributes()
method call: that is, the returned
attribute set's contents will not be updated if this print
service's attribute set's contents change in the future. To detect
changes in attribute values, call getAttributes()
again
and compare the new attribute set to the previous attribute set;
alternatively, register a listener for print service events.<T extends PrintServiceAttribute> T getAttribute(Class<T> category)
category
- the category of a PrintServiceAttribute supported
by this service - may not be null.NullPointerException
- if the category is null.IllegalArgumentException
- (unchecked exception) if category
is not a
Class
that implements interface
PrintServiceAttribute
.DocFlavor[] getSupportedDocFlavors()
PrintService
. A print data format is
designated by a "doc
flavor" (class DocFlavor
)
consisting of a MIME type plus a print data representation class.
Note that some doc flavors may not be supported in combination
with all attributes. Use getUnsupportedAttributes(..)
to validate specific combinations.
boolean isDocFlavorSupported(DocFlavor flavor)
DocFlavor
. This is a convenience method to determine
if the DocFlavor
would be a member of the result of
getSupportedDocFlavors()
.
Note that some doc flavors may not be supported in combination
with all attributes. Use getUnsupportedAttributes(..)
to validate specific combinations.
flavor
- the DocFlavor
to query for support.true
if this print service supports the
specified DocFlavor
; false
otherwise.NullPointerException
- (unchecked exception) Thrown if flavor
is null.Class<?>[] getSupportedAttributeCategories()
Class
that implements interface
Attribute
. This method returns
just the attribute categories that are supported; it does not
return the particular attribute values that are supported.
This method returns all the printing attribute
categories this print service supports for any possible job.
Some categories may not be supported in a particular context (ie
for a particular DocFlavor
).
Use one of the methods that include a DocFlavor
to
validate the request before submitting it, such as
getSupportedAttributeValues(..)
.
boolean isAttributeCategorySupported(Class<? extends Attribute> category)
Class
that implements interface Attribute
. This method tells whether the attribute category is
supported; it does not tell whether a particular attribute value
is supported.
Some categories may not be supported in a particular context (ie
for a particular DocFlavor
).
Use one of the methods which include a DocFlavor
to
validate the request before submitting it, such as
getSupportedAttributeValues(..)
.
This is a convenience method to determine if the category
would be a member of the result of
getSupportedAttributeCategories()
.
category
- Printing attribute category to test. It must be a
Class
that implements
interface
Attribute
.true
if this print service supports
specifying a doc-level or
job-level attribute in category
in a Print
Request; false
if it doesn't.NullPointerException
- (unchecked exception) Thrown if category
is null.IllegalArgumentException
- (unchecked exception) Thrown if category
is not a
Class
that implements interface
Attribute
.Object getDefaultAttributeValue(Class<? extends Attribute> category)
Attribute
. If a client sets
up a print job and does not specify any attribute value in the
given category, this Print Service will use the
default attribute value instead.
Some attributes may not be supported in a particular context (ie
for a particular DocFlavor
).
Use one of the methods that include a DocFlavor
to
validate the request before submitting it, such as
getSupportedAttributeValues(..)
.
Not all attributes have a default value. For example the
service will not have a defaultvalue for RequestingUser
i.e. a null return for a supported category means there is no
service default value for that category. Use the
isAttributeCategorySupported(Class)
method to
distinguish these cases.
category
- Printing attribute category for which the default
attribute value is requested. It must be a Class
that implements interface
Attribute
.category
, or null
if this Print Service does not support specifying a doc-level or
job-level attribute in category
in a Print
Request, or the service does not have a default value
for this attribute.NullPointerException
- (unchecked exception) Thrown if category
is null.IllegalArgumentException
- (unchecked exception) Thrown if category
is not a
Class
that implements interface Attribute
.Object getSupportedAttributeValues(Class<? extends Attribute> category, DocFlavor flavor, AttributeSet attributes)
Attribute
.
If flavor
is null and attributes
is null
or is an empty set, this method returns all the printing attribute
values this Print Service supports for any possible job. If
flavor
is not null or attributes
is not
an empty set, this method returns just the printing attribute values
that are compatible with the given doc flavor and/or set of attributes.
That is, a null return value may indicate that specifying this attribute
is incompatible with the specified DocFlavor.
Also if DocFlavor is not null it must be a flavor supported by this
PrintService, else IllegalArgumentException will be thrown.
If the attributes
parameter contains an Attribute whose
category is the same as the category
parameter, the service
must ignore this attribute in the AttributeSet.
DocAttribute
s which are to be specified on the
Doc
must be included in this set to accurately
represent the context.
This method returns an Object because different printing attribute
categories indicate the supported attribute values in different ways.
The documentation for each printing attribute in package javax.print.attribute.standard
describes how each attribute indicates its supported values. Possible
ways of indicating support include:
getCategory(Class)
.
category
- Printing attribute category to test. It must be a
Class
that implements
interface Attribute
.flavor
- Doc flavor for a supposed job, or null.attributes
- Set of printing attributes for a supposed job
(both job-level attributes and document-level
attributes), or null.category
,
or null if this Print Service does not support specifying a
doc-level or job-level attribute in category
in
a Print Request.NullPointerException
- (unchecked exception) Thrown if category
is null.IllegalArgumentException
- (unchecked exception) Thrown if category
is not a
Class
that implements interface Attribute
, or
DocFlavor
is not supported by this service.boolean isAttributeValueSupported(Attribute attrval, DocFlavor flavor, AttributeSet attributes)
Attribute
.
If flavor
is null and attributes
is null or
is an empty set, this method tells whether this Print Service supports
the given printing attribute value for some possible combination of doc
flavor and set of attributes. If flavor
is not null or
attributes
is not an empty set, this method tells whether
this Print Service supports the given printing attribute value in
combination with the given doc flavor and/or set of attributes.
Also if DocFlavor is not null it must be a flavor supported by this PrintService, else IllegalArgumentException will be thrown.
DocAttribute
s which are to be specified on the
Doc
must be included in this set to accurately
represent the context.
This is a convenience method to determine if the value
would be a member of the result of
getSupportedAttributeValues(...)
.
attrval
- Printing attribute value to test.flavor
- Doc flavor for a supposed job, or null.attributes
- Set of printing attributes for a supposed job
(both job-level attributes and document-level
attributes), or null.attrval
as a doc-level or job-level attribute in a
Print Request, false if it doesn't.NullPointerException
- (unchecked exception) if attrval
is null.IllegalArgumentException
- if flavor is not supported by
this PrintService.AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes)
DocAttribute
s which are to be specified on the
Doc
must be included in this set to accurately
represent the context.
If the return value is non-null, all attributes in the returned set are unsupported with this DocFlavor. The returned set does not distinguish attribute categories that are unsupported from unsupported attribute values.
A supported print request can then be created by removing all unsupported attributes from the original attribute set, except in the case that the DocFlavor is unsupported.
If any attributes are unsupported only because they are in conflict with other attributes then it is at the discretion of the service to select the attribute(s) to be identified as the cause of the conflict.
Use isDocFlavorSupported()
to verify that a DocFlavor
is supported before calling this method.
flavor
- Doc flavor to test, or nullattributes
- Set of printing attributes for a supposed job
(both job-level attributes and document-level
attributes), or null.IllegalArgumentException
- ifflavor
is
not supported by this PrintService.ServiceUIFactory getServiceUIFactory()
ServiceUIFactory
for more information.boolean equals(Object obj)
Clients should call this method to determine if two services are referring to the same underlying service.
Services must implement this method and return true only if the service objects being compared may be used interchangeably by the client. Services are free to return the same object reference to an underlying service if that, but clients must not depend on equality of reference.
equals
in class Object
obj
- the reference object with which to compare.Object.hashCode()
,
HashMap
int hashCode()
equals(Object)
.hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2024, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.