Provides the basic interfaces and classes of the Java Print Service API.
See: Description
Interface Summary | |
---|---|
AttributeException |
AttributeException specifies two methods a specific
subclass of {@link javax.print.PrintException} may implement to
provide further information of printing errors if unsupported
attribute classes or values of attributes are involved.
|
CancelablePrintJob |
CancelablePrintJob represents a print job which can be
canceled.
|
Doc |
Doc specifies the interface for print services how to obtain
the print data and document specific attributes for printing.
|
DocPrintJob |
DocPrintJob represents a print job which supports printing
of a single document.
|
FlavorException |
FlavorException specifies a method a specific
subclass of {@link javax.print.PrintException} may implement to
provide further information of printing errors if unsupported
document flavors are involved.
|
MultiDoc |
MultiDoc defines the interface for objects providing multiple
documents for use in a print job.
|
MultiDocPrintJob |
MultiDocPrintJob represents a print job which supports
printing of multiple documents as one print job.
|
MultiDocPrintService |
MultiDocPrintService represents print services that are
capable of printing multiple documents as one print job. |
PrintService |
A PrintService represents a printer available for printing.
|
URIException |
URIException specifies methods a specific subclass of
{@link javax.print.PrintException} may implement to provide further
informations of printing errors if URI problems are involved.
|
Class Summary | |
---|---|
DocFlavor |
DocFlavor provides a description of the format in which the
print data will be supplied in a print job to the print service.
|
DocFlavor.BYTE_ARRAY |
Predefined static DocFlavor objects for document
types which use a byte array for the print data representation.
|
DocFlavor.CHAR_ARRAY |
Predefined static DocFlavor objects for document
types which use a char array for the print data representation.
|
DocFlavor.INPUT_STREAM |
Predefined static DocFlavor objects for document
types which use an InputStream to retrieve the print data.
|
DocFlavor.READER |
Predefined static DocFlavor objects for document
types which use an Reader to retrieve the print data.
|
DocFlavor.SERVICE_FORMATTED |
Predefined static DocFlavor objects for document
types which use service formatted print data.
|
DocFlavor.STRING |
Predefined static DocFlavor objects for document
types which use a String for the print data representation.
|
DocFlavor.URL |
Predefined static DocFlavor objects for document
types which have an URL where to retrieve the print data.
|
PrintServiceLookup |
PrintServiceLookup implementations provide a way to lookup
print services based on different constraints.
|
ServiceUI |
ServiceUI provides a method to create a graphical
print dialog.
|
ServiceUIFactory |
ServiceUIFactory enables print services to provide additional
user interface dialogs.
|
SimpleDoc |
Simple implementation of the Doc interface capable of handling
the predefined document flavors of DocFlavor .
|
StreamPrintService |
StreamPrintService is a special print service capable of
printing into a supplied output stream.
|
StreamPrintServiceFactory |
StreamPrintServiceFactory provides a static method to lookup
registered factories to construct StreamPrintService instances.
|
Exception Summary | |
---|---|
PrintException |
PrintException is used to report exceptions during the
usage of a print service implementation.
|
The Java Print Service API enables programmers to:
OutputStream
. Available stream print services are
discovered via the static methods in the
StreamPrintServiceFactory factory. The query can be constrained by supplying
the the requested document format support and the needed output format.
javax.print.attribute
. The actual available printing attributes
are implemented in the javax.print.attribute.standard
package.
PagesPerMinute
providing the number of pages a printer can print
per minute. Status attributes like the PrinterState
attribute
gives the current state (e.g. printer currently processes or is idle) of the
printer.NumberOfInterveningJobs
attribute provides the number of jobs
ahead in the print service queue before this job. Status attributes like the
JobState
attribute gives the current state of the print job (like
pending, processing or canceled).import java.io.*;
import javax.print.*; import javax.print.attribute.*; import javax.print.attribute.standard.*; import javax.print.event.*;
public class Beispiel { public static void main(String[] args) { // Using the predefined doc flavor for postscript mimetype DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
// Looking for printservice supporting this doc flavor PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
// Just take the first PrintService service = services[0]; System.out.println("Name :" + service.getName());
try { // Create a print job DocPrintJob job = service.createPrintJob();
// We want to print a file so we construct an inputstream // on the file to supply the print data as given in the doc flavor File file = new File("File.ps"); InputStream stream = new FileInputStream(file);
// Build a attribute set with the wanted printing attributes HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new Copies(2)); // two copies attr.add(new PageRanges(2, 7)); // only the 2-7 pages
// Construct a doc object with the provided class SimpleDoc SimpleDoc doc = new SimpleDoc(stream, flavor, null);
// register us as the print - use the adapter class // and override the interesing failure condition job.addPrintJobListener(new PrintJobAdapter() { public void printJobFailed(PrintJobEvent arg0) { System.out.println("The PrintJob failed."); } });
// start the printing process job.print(doc, attr);
// lets assume we want to cancel it if (job instanceof CancelablePrintJob) { CancelablePrintJob cancelJob = (CancelablePrintJob) job; cancelJob.cancel(); }
} catch (PrintException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
Since: 1.4