jdk/src/java.desktop/share/classes/javax/print/package.html
author psadhukhan
Tue, 31 May 2016 12:29:57 +0530
changeset 39014 bb1c478f025b
parent 25859 3317bb8137f4
permissions -rw-r--r--
4957035: Code given in api is not compilable: docs/api/javax/print/package-summary.html Reviewed-by: serb, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21254
f6d36ee3f269 8025824: [cleanup] Fix tidy errors and warnings in preformatted HTML files related to 2d/awt/swing
yan
parents: 5551
diff changeset
     1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
<html>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
<head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
<title>javax.print package</title>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
<!--
25770
d132697706ea 8037511: Tidy warnings cleanup for java.awt - 2d part
avstepan
parents: 23010
diff changeset
     6
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    11
published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    13
by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
5551
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    25
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    26
or visit www.oracle.com if you need additional information or have any
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    27
questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
</head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
<body bgcolor="white">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
Provides the principal classes and interfaces for the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
Java<sup><font size="-2">TM</font></sup> Print Service API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
The Java Print Service API enables client and server applications to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
<li>Discover and select print services based on their capabilities 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
<li>Specify the format of print data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
<li>Submit print jobs to services that support the document type to 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
<h3>Print Service Discovery</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
An application invokes the static methods of the abstract class 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
{@link javax.print.PrintServiceLookup PrintServiceLookup} to locate print 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
services that have the capabilities to satisfy the application's print 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
request.  For example, to print a double-sided document, the application 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
first needs to find printers that have the double-sided printing capability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
The JDK includes <code>PrintServiceLookup</code> implementations that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
can locate the standard platform printers.  To locate other types of printers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
such as IPP printers or JINI printers, a print-service provider can write 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
implementations of <code>PrintServiceLookup</code>.  The print-service provider 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
can dynamically install these <code>PrintServiceLookup</code> implementations 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
using the 
21254
f6d36ee3f269 8025824: [cleanup] Fix tidy errors and warnings in preformatted HTML files related to 2d/awt/swing
yan
parents: 5551
diff changeset
    56
<a href="../../../technotes/guides/jar/jar.html#Service%20Provider">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
SPI JAR file specification</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
<h3>Attribute Definitions</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
The {@link javax.print.attribute} and {@link javax.print.attribute.standard} 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
packages define print attributes, which describe the capabilities of a print 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
service, specify the requirements of a print job, and track the progress of 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
a print job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
The <code>javax.print.attribute</code> package describes the types of attributes and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
how they can be collected into sets.  The <code>javax.print.attribute.standard</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
package enumerates all of the standard attributes supported by the API, most
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
of which are implementations of attributes specified in the IETF Specification, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
<a href="http://www.ietf.org/rfc/rfc2911.txt">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
RFC 2911 Internet Printing Protocol, 1.1: Model and Semantics</a>, dated 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
September 2000.  The attributes specified in <code>javax.print.attribute.standard</code>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21254
diff changeset
    73
include common capabilities, such as: resolution, copies, media sizes, 
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
job priority, and page ranges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
<h3>Document Type Specification</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
The {@link javax.print.DocFlavor DocFlavor} class represents the print data 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
format, such as JPEG or PostScript.  A <code>DocFlavor</code> object 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
consists of a MIME type, which describes the format, and a document 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
representation class name that indicates how the document is delivered 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
to the printer or output stream.  An application uses the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
<code>DocFlavor</code> and an attribute set to find printers that can 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
print the document type specified by the <code>DocFlavor</code> and have 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
the capabilities specified by the attribute set.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
<h3>Using the API</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
A typical application using the Java Print Service API performs these steps
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
to process a print request:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
<ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
<li>Chooses a <code>DocFlavor</code>.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
<li>Creates a set of attributes.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
<li>Locates a print service that can handle the print request as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
by the <code>DocFlavor</code> and the attribute set.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
<li>Creates a {@link javax.print.Doc Doc} object encapsulating the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
<code>DocFlavor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
and the actual print data, which can take many forms including: a Postscript 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
file, a JPEG image, a URL, or plain text.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
<li>Gets a print job, represented by {@link javax.print.DocPrintJob DocPrintJob},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 from the print service.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
<li>Calls the print method of the print job.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
</ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
The following code sample demonstrates a typical use of the Java Print 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
Service API: locating printers that can print five double-sided copies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
of a Postscript document on size A4 paper, creating a print job from 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
one of the returned print services, and calling print.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
21254
f6d36ee3f269 8025824: [cleanup] Fix tidy errors and warnings in preformatted HTML files related to 2d/awt/swing
yan
parents: 5551
diff changeset
   109
<blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
FileInputStream psStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   psStream = new FileInputStream("file.ps");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
} catch (FileNotFoundException ffne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
if (psStream == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.POSTSCRIPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
Doc myDoc = new SimpleDoc(psStream, psInFormat, null);  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
PrintRequestAttributeSet aset = 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
	new HashPrintRequestAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
aset.add(new Copies(5));
39014
bb1c478f025b 4957035: Code given in api is not compilable: docs/api/javax/print/package-summary.html
psadhukhan
parents: 25859
diff changeset
   125
aset.add(MediaSizeName.ISO_A4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
aset.add(Sides.DUPLEX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
PrintService[] services = 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  PrintServiceLookup.lookupPrintServices(psInFormat, aset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
if (services.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
   DocPrintJob job = services[0].createPrintJob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
   try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
	job.print(myDoc, aset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
   } catch (PrintException pe) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
}
21254
f6d36ee3f269 8025824: [cleanup] Fix tidy errors and warnings in preformatted HTML files related to 2d/awt/swing
yan
parents: 5551
diff changeset
   135
</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
Please note: In the javax.print APIs, a null reference parameter to methods 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
is incorrect unless explicitly documented on the method as having a meaningful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
interpretation. Usage to the contrary is incorrect coding and may result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
in a run time exception either immediately or at some later time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
IllegalArgumentException and NullPointerException are examples of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
typical and acceptable run time exceptions for such cases.
25770
d132697706ea 8037511: Tidy warnings cleanup for java.awt - 2d part
avstepan
parents: 23010
diff changeset
   144
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
@since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
</body>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
</html>