Path: blob/master/src/java.desktop/share/classes/javax/print/package-info.java
41153 views
/*1* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* Provides the principal classes and interfaces for the Java Print27* Service API. The Java Print Service API enables client and server28* applications to:29* <ul>30* <li>Discover and select print services based on their capabilities31* <li>Specify the format of print data32* <li>Submit print jobs to services that support the document type to be33* printed.34* </ul>35*36* <h2>Print Service Discovery</h2>37* An application invokes the static methods of the abstract class38* {@link javax.print.PrintServiceLookup PrintServiceLookup} to locate print39* services that have the capabilities to satisfy the application's print40* request. For example, to print a double-sided document, the application first41* needs to find printers that have the double-sided printing capability.42* <p>43* The JDK includes {@code PrintServiceLookup} implementations that can locate44* the standard platform printers. To locate other types of printers, such as45* IPP printers or JINI printers, a print-service provider can write46* implementations of {@code PrintServiceLookup}. The print-service provider can47* dynamically install these {@code PrintServiceLookup} implementations using48* the {@link java.util.ServiceLoader} facility.49*50* <h2>Attribute Definitions</h2>51* The {@link javax.print.attribute} and {@link javax.print.attribute.standard}52* packages define print attributes, which describe the capabilities of a print53* service, specify the requirements of a print job, and track the progress of a54* print job.55* <p>56* The {@code javax.print.attribute} package describes the types of attributes57* and how they can be collected into sets. The58* {@code javax.print.attribute.standard} package enumerates all of the standard59* attributes supported by the API, most of which are implementations of60* attributes specified in the IETF Specification,61* <a href="http://www.ietf.org/rfc/rfc2911.txt">RFC 2911 Internet Printing62* Protocol, 1.1: Model and Semantics</a>, dated September 2000. The attributes63* specified in {@code javax.print.attribute.standard} include common64* capabilities, such as: resolution, copies, media sizes, job priority, and65* page ranges.66*67* <h2>Document Type Specification</h2>68* The {@link javax.print.DocFlavor DocFlavor} class represents the print data69* format, such as JPEG or PostScript. A {@code DocFlavor} object consists of a70* MIME type, which describes the format, and a document representation class71* name that indicates how the document is delivered to the printer or output72* stream. An application uses the {@code DocFlavor} and an attribute set to73* find printers that can print the document type specified by the74* {@code DocFlavor} and have the capabilities specified by the attribute set.75*76* <h2>Using the API</h2>77* A typical application using the Java Print Service API performs these steps78* to process a print request:79* <ol>80* <li>Chooses a {@code DocFlavor}.81* <li>Creates a set of attributes.82* <li>Locates a print service that can handle the print request as specified83* by the {@code DocFlavor} and the attribute set.84* <li>Creates a {@link javax.print.Doc Doc} object encapsulating the85* {@code DocFlavor} and the actual print data, which can take many forms86* including: a Postscript file, a JPEG image, a {@code URL}, or plain text.87* <li>Gets a print job, represented by88* {@link javax.print.DocPrintJob DocPrintJob}, from the print service.89* <li>Calls the print method of the print job.90* </ol>91* The following code sample demonstrates a typical use of the Java Print92* Service API: locating printers that can print five double-sided copies of a93* Postscript document on size A4 paper, creating a print job from one of the94* returned print services, and calling print.95* <blockquote>96* <pre>{@code97* FileInputStream psStream;98* try {99* psStream = new FileInputStream("file.ps");100* } catch (FileNotFoundException ffne) {101* }102* if (psStream == null) {103* return;104* }105* DocFlavor psInFormat = DocFlavor.INPUT_STREAM.POSTSCRIPT;106* Doc myDoc = new SimpleDoc(psStream, psInFormat, null);107* PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();108* aset.add(new Copies(5));109* aset.add(MediaSizeName.ISO_A4);110* aset.add(Sides.DUPLEX);111* PrintService[] services =112* PrintServiceLookup.lookupPrintServices(psInFormat, aset);113* if (services.length > 0) {114* DocPrintJob job = services[0].createPrintJob();115* try {116* job.print(myDoc, aset);117* } catch (PrintException pe) {}118* }119* }</pre>120* </blockquote>121* <p>122* Please note: In the {@code javax.print} APIs, a {@code null} reference123* parameter to methods is incorrect unless explicitly documented on the method124* as having a meaningful interpretation. Usage to the contrary is incorrect125* coding and may result in a run time exception either immediately or at some126* later time. {@code IllegalArgumentException} and {@code NullPointerException}127* are examples of typical and acceptable run time exceptions for such cases.128*129* @since 1.4130*/131package javax.print;132133134