- java.lang.Object
-
- javafx.print.Printer
-
public final class Printer extends Object
A Printer instance represents the destination for a print job.Printers may be enumerated and selected for use with a print job.
The configuration of the printer default settings are then used to populate the initial settings for a job.
Since the availability of printers may change during the execution of a program, due to administrative actions, a long running program which has cached a printer which has since been taken off-line, may create a job using that instance, but printing will fail.
- Since:
- JavaFX 8.0
-
-
Property Summary
Properties Type Property Description static ReadOnlyObjectProperty<Printer>
defaultPrinter
A read only object property representing the current default printer.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Printer.MarginType
The MarginType is used to determine the printable area of a PageLayout.
-
Method Summary
Modifier and Type Method Description PageLayout
createPageLayout(Paper paper, PageOrientation orient, double lMargin, double rMargin, double tMargin, double bMargin)
Obtain a new PageLayout for this printer using the specified parameters.PageLayout
createPageLayout(Paper paper, PageOrientation orient, Printer.MarginType mType)
Obtain a new PageLayout instance for this printer using the specified parameters.static ReadOnlyObjectProperty<Printer>
defaultPrinterProperty()
A read only object property representing the current default printer.static ObservableSet<Printer>
getAllPrinters()
Retrieve the installed printers.PageLayout
getDefaultPageLayout()
Return the default page layout for this printer.static Printer
getDefaultPrinter()
Retrieve the default printer.String
getName()
Return the name used by the underlying system to identify the printer to users and/or applications.PrinterAttributes
getPrinterAttributes()
Retrieves the delegate object encapsulating the printer attributes and capabilities.String
toString()
-
-
-
Property Detail
-
defaultPrinter
public static ReadOnlyObjectProperty<Printer> defaultPrinterProperty
A read only object property representing the current default printer. If there are no installed printers, the wrapped value will be null.- See Also:
getDefaultPrinter()
-
-
Method Detail
-
getAllPrinters
public static ObservableSet<Printer> getAllPrinters()
Retrieve the installed printers. The set of printers may be dynamic. Consequently there is no guarantee that the result will be the same from call to call, but should change only as a result of the default changing in the environment of the application.Note: since printers may be installed, but offline, then the application may want to query the status of a printer before using it.
- Returns:
- may be null if there are no printers.
- Throws:
SecurityException
- if the application does not have permission to browse printers.
-
defaultPrinterProperty
public static ReadOnlyObjectProperty<Printer> defaultPrinterProperty()
A read only object property representing the current default printer. If there are no installed printers, the wrapped value will be null.- See Also:
getDefaultPrinter()
-
getDefaultPrinter
public static Printer getDefaultPrinter()
Retrieve the default printer. May return null if no printers are installed.The configuration of available printers may be dynamic. Consequently there is no guarantee that the result will be the same from call to call, but should change only as a result of the default changing in the environment of the application.
- Returns:
- default printer or null.
- Throws:
SecurityException
- if the application does not have permission to browse printers.
-
getName
public String getName()
Return the name used by the underlying system to identify the printer to users and/or applications.- Returns:
- printer name.
-
getPrinterAttributes
public PrinterAttributes getPrinterAttributes()
Retrieves the delegate object encapsulating the printer attributes and capabilities.- Returns:
- printer attributes.
-
getDefaultPageLayout
public PageLayout getDefaultPageLayout()
Return the default page layout for this printer.- Returns:
- default page layout.
-
createPageLayout
public PageLayout createPageLayout(Paper paper, PageOrientation orient, Printer.MarginType mType)
Obtain a new PageLayout instance for this printer using the specified parameters. The paper should be one of the supported papers and the orientation should be a supported orientation. If the printer cannot support the layout as specified, it will adjust the returned layout to a supported configuration- Parameters:
paper
- The paper to useorient
- The orientation to usemType
- the margin type to use- Returns:
- PageLayout based on the specified parameters.
- Throws:
NullPointerException
- if any of the parameters are null.
-
createPageLayout
public PageLayout createPageLayout(Paper paper, PageOrientation orient, double lMargin, double rMargin, double tMargin, double bMargin)
Obtain a new PageLayout for this printer using the specified parameters. The paper should be one of the supported papers and the orientation should be a supported orientation.Margin values are specified in 1/72 of an inch points. Margins will be validated against the printer supported margins, and adjusted if necessary. This method is generally useful to a client that wants margins that are different (eg wider) than the default margins, such as 1" at top and bottom and 0.5" to the left and right.
A client that needs to know what margin values are legal should first obtain a PageLayout using the
HARDWARE_MINIMUM
margins.If the printer cannot support the layout as specified, it will adjust the returned layout to a supported configuration
- Parameters:
paper
- The paper to useorient
- The orientation to uselMargin
- the left margin to use in pts.rMargin
- the right margin to use in pts.tMargin
- the top margin to use in pts.bMargin
- the bottom margin to use in pts.- Returns:
- PageLayout based on the specified parameters.
- Throws:
NullPointerException
- if paper or orient are null.IllegalArgumentException
- if any of the margins values are less than zero.
-
-