Methods Summary |
---|
public abstract void | cancel()Cancels a print job that is in progress. If
{@link #print() print} has been called but has not
returned then this method signals
that the job should be cancelled at the next
chance. If there is no print job in progress then
this call does nothing.
|
public abstract java.awt.print.PageFormat | defaultPage(java.awt.print.PageFormat page)Clones the PageFormat argument and alters the
clone to describe a default page size and orientation.
|
public java.awt.print.PageFormat | defaultPage()Creates a new PageFormat instance and
sets it to a default size and orientation.
return defaultPage(new PageFormat());
|
public abstract int | getCopies()Gets the number of copies to be printed.
|
public abstract java.lang.String | getJobName()Gets the name of the document to be printed.
|
public javax.print.PrintService | getPrintService()Returns the service (printer) for this printer job.
Implementations of this class which do not support print services
may return null;
return null;
|
public static java.awt.print.PrinterJob | getPrinterJob()Creates and returns a 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
{@link #print() 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
{@link #lookupPrintServices() lookupPrintServices} is not empty.
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPrintJobAccess();
}
return (PrinterJob) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
String nm = System.getProperty("java.awt.printerjob", null);
try {
return (PrinterJob)Class.forName(nm).newInstance();
} catch (ClassNotFoundException e) {
throw new AWTError("PrinterJob not found: " + nm);
} catch (InstantiationException e) {
throw new AWTError("Could not instantiate PrinterJob: " + nm);
} catch (IllegalAccessException e) {
throw new AWTError("Could not access PrinterJob: " + nm);
}
}
});
|
public abstract java.lang.String | getUserName()Gets the name of the printing user.
|
public abstract boolean | isCancelled()Returns true if a print job is
in progress, but is going to be cancelled
at the next opportunity; otherwise returns
false .
|
public static javax.print.PrintService[] | lookupPrintServices()A convenience method which looks up 2D print services.
Services returned from this method may be installed on
PrinterJob s which support print services.
Calling this method is equivalent to calling
{@link javax.print.PrintServiceLookup#lookupPrintServices(
DocFlavor, AttributeSet)
PrintServiceLookup.lookupPrintServices() }
and specifying a Pageable DocFlavor.
return PrintServiceLookup.
lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
|
public static javax.print.StreamPrintServiceFactory[] | lookupStreamPrintServices(java.lang.String mimeType)A convenience method which locates factories for stream print
services which can image 2D graphics.
Sample usage :
FileOutputStream outstream;
StreamPrintService psPrinter;
String psMimeType = "application/postscript";
StreamPrintServiceFactory[] factories =
PrinterJob.lookupStreamPrintServices(psMimeType);
if (factories.length > 0) {
try {
outstream = new File("out.ps");
psPrinter = factories[0].getPrintService(fos);
// psPrinter can now be set as the service on a PrinterJob
} catch (FileNotFoundException e) {
}
}
Services returned from this method may be installed on
PrinterJob instances which support print services.
Calling this method is equivalent to calling
{@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
} and specifying a Pageable DocFlavor.
return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
DocFlavor.SERVICE_FORMATTED.PAGEABLE,
mimeType);
|
public abstract java.awt.print.PageFormat | pageDialog(java.awt.print.PageFormat page)Displays a dialog that allows modification of a
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.
|
public java.awt.print.PageFormat | pageDialog(javax.print.attribute.PrintRequestAttributeSet attributes)A convenience method which displays a cross-platform page setup dialog.
The choices available will reflect the print service currently
set on this PrinterJob.
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.
if (attributes == null) {
throw new NullPointerException("attributes");
}
return pageDialog(defaultPage());
|
public abstract void | print()Prints a set of pages.
|
public void | print(javax.print.attribute.PrintRequestAttributeSet attributes)Prints a set of pages using the settings in the attribute
set. The default implementation ignores the attribute set.
Note that some attributes may be set directly on the PrinterJob
by equivalent method calls, (for example), copies:
setcopies(int) , job name: setJobName(String)
and specifying media size and orientation though the
PageFormat object.
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
attributes parameter to this method is examined
for attributes which specify media (by size), orientation, and
imageable area, and those are used to construct a new PageFormat
which is passed to the Printable object's print() method.
See {@link Printable} for an explanation of the required
behaviour of a Printable to ensure optimal printing via PrinterJob.
For clients of the Pageable interface, the PageFormat will always
be as supplied by that interface, on a per page basis.
These behaviours allow an application to directly pass the
user settings returned from
printDialog(PrintRequestAttributeSet attributes to
this print() method.
print();
|
public abstract boolean | printDialog()Presents a dialog to the user for changing the properties of
the print job.
This method will display a native dialog if a native print
service is selected, and user choice of printers will be restricted
to these native print services.
To present the cross platform print dialog for all services,
including native ones instead use
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.
|
public boolean | printDialog(javax.print.attribute.PrintRequestAttributeSet attributes)A convenience method which displays a cross-platform print dialog
for all services which are capable of printing 2D graphics using the
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
print(PrintRequestAttributeSet) method. If using
the Pageable interface, clients which intend to use media selected
by the user must create a PageFormat derived from the user's
selections.
If the user cancels the dialog, the attributes will not reflect
any changes made by the user.
if (attributes == null) {
throw new NullPointerException("attributes");
}
return printDialog();
|
public abstract void | setCopies(int copies)Sets the number of copies to be printed.
|
public abstract void | setJobName(java.lang.String jobName)Sets the name of the document to be printed.
The document name can not be null .
|
public abstract void | setPageable(java.awt.print.Pageable document)Queries document for the number of pages and
the PageFormat and Printable for each
page held in the Pageable instance,
document .
|
public void | setPrintService(javax.print.PrintService service)Associate this PrinterJob with a new PrintService.
This method is overridden by subclasses which support
specifying a Print Service.
Throws PrinterException if the specified service
cannot support the Pageable and
Printable interfaces necessary to support 2D printing.
throw new PrinterException(
"Setting a service is not supported on this class");
|
public abstract void | setPrintable(java.awt.print.Printable painter)Calls painter to render the pages. The pages in the
document to be printed by this
PrinterJob are rendered by the {@link Printable}
object, painter . The {@link PageFormat} for each page
is the default page format.
|
public abstract void | setPrintable(java.awt.print.Printable painter, java.awt.print.PageFormat format)Calls 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 .
|
public abstract java.awt.print.PageFormat | validatePage(java.awt.print.PageFormat page)Returns the clone of 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.
|