java.lang.Objectjava.awt.print.PrinterJob
Direct Known Subclasses:
PrinterJobImpl, NoPrinterJob
PrinterJob
class is the principal class that controls
printing. An application calls methods in this class to set up a job,
optionally to invoke a print dialog with the user, and then to print
the pages of the job.
Constructor: |
---|
PrinterJob object should be created using the
static getPrinterJob method. |
Method from java.awt.print.PrinterJob Summary: |
---|
cancel, defaultPage, defaultPage, getCopies, getJobName, getPageFormat, getPrintService, getPrinterJob, getUserName, isCancelled, lookupPrintServices, lookupStreamPrintServices, pageDialog, pageDialog, print, print, printDialog, printDialog, setCopies, setJobName, setPageable, setPrintService, setPrintable, setPrintable, validatePage |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from java.awt.print.PrinterJob Detail: |
---|
|
PageFormat instance and
sets it to a default size and orientation. |
PageFormat argument and alters the
clone to describe a default page size and orientation. |
|
|
PageFormat with values consistent with those
supported by the current PrintService for this job
(ie the value returned by getPrintService() ) and media,
printable area and orientation contained in attributes .
Calling this method does not update the job.
It is useful for clients that have a set of attributes obtained from
|
|
PrinterJob which is initially
associated with the default printer.
If no printers are available on the system, a PrinterJob will still
be returned from this method, but getPrintService()
will return null , and calling
print with this PrinterJob might
generate an exception. Applications that need to determine if
there are suitable printers before creating a PrinterJob
should ensure that the array returned from
lookupPrintServices is not empty. |
|
true if a print job is
in progress, but is going to be cancelled
at the next opportunity; otherwise returns
false . |
PrinterJob s which support print services.
Calling this method is equivalent to calling
DocFlavor, AttributeSet)
PrintServiceLookup.lookupPrintServices()
and specifying a Pageable DocFlavor. |
FileOutputStream outstream; StreamPrintService psPrinter; String psMimeType = "application/postscript"; PrinterJob pj = PrinterJob.getPrinterJob(); StreamPrintServiceFactory[] factories = PrinterJob.lookupStreamPrintServices(psMimeType); if (factories.length > 0) { try { outstream = new File("out.ps"); psPrinter = factories[0].getPrintService(outstream); // psPrinter can now be set as the service on a PrinterJob pj.setPrintService(psPrinter) } catch (Exception e) { e.printStackTrace(); } }Services returned from this method may be installed on PrinterJob instances which support print services.
Calling this method is equivalent to calling
String)
and specifying a Pageable DocFlavor. |
PageFormat instance.
The page argument is used to initialize controls
in the page setup dialog.
If the user cancels the dialog then this method returns the
original page object unmodified.
If the user okays the dialog then this method returns a new
PageFormat object with the indicated changes.
In either case, the original page object is
not modified. |
The attributes parameter on input will reflect the client's required initial selections in the user dialog. Attributes which are not specified display using the default for the service. On return it will reflect the user's choices. Selections may be updated by the implementation to be consistent with the supported values for the currently selected print service. The return value will be a PageFormat equivalent to the selections in the PrintRequestAttributeSet. If the user cancels the dialog, the attributes will not reflect any changes made by the user, and the return value will be null. |
|
Note that some attributes may be set directly on the PrinterJob
by equivalent method calls, (for example), copies:
If a supported attribute-value is specified in this attribute set,
it will take precedence over the API settings for this print()
operation only.
The following behaviour is specified for PageFormat:
If a client uses the Printable interface, then the
These behaviours allow an application to directly pass the
user settings returned from
|
printDialog(PrintRequestAttributeSet) .
PrinterJob implementations which can use PrintService's will update the PrintService for this PrinterJob to reflect the new service selected by the user. |
Pageable interface. The selected printer when the
dialog is initially displayed will reflect the print service currently
attached to this print job.
If the user changes the print service, the PrinterJob will be
updated to reflect this, unless the user cancels the dialog.
As well as allowing the user to select the destination printer,
the user can also select values of various print request attributes.
The attributes parameter on input will reflect the applications required initial selections in the user dialog. Attributes not specified display using the default for the service. On return it will reflect the user's choices. Selections may be updated by the implementation to be consistent with the supported values for the currently selected print service. As the user scrolls to a new print service selection, the values copied are based on the settings for the previous service, together with any user changes. The values are not based on the original settings supplied by the client.
With the exception of selected printer, the PrinterJob state is
not updated to reflect the user's changes.
For the selections to affect a printer job, the attributes must
be specified in the call to the
|
|
null . |
document for the number of pages and
the PageFormat and Printable for each
page held in the Pageable instance,
document . |
PrinterException if the specified service
cannot support the Pageable and
Printable interfaces necessary to support 2D printing. |
painter to render the pages. The pages in the
document to be printed by this
PrinterJob are rendered by the Printable
object, painter . The PageFormat for each page
is the default page format. |
painter to render the pages in the specified
format . The pages in the document to be printed by
this PrinterJob are rendered by the
Printable object, painter . The
PageFormat of each page is format . |
page with its settings
adjusted to be compatible with the current printer of this
PrinterJob . For example, the returned
PageFormat could have its imageable area
adjusted to fit within the physical area of the paper that
is used by the current printer. |