public final class Printer
- Object
- Printer
Cross platform printing API that hands a document to the platform printing system, typically by popping up the native print dialog where the user picks a printer and options.
The document is a file in FileSystemStorage
identified by its path and mime type. All platforms accept PDF
(application/pdf) and common image types (image/png, image/jpeg);
other mime types fail with PrintResult.STATUS_FAILED on platforms that
can’t render them.
Sample usage:
if (Printer.isPrintingSupported()) {
Printer.print(reportPath, "application/pdf", new PrintResultListener() {
public void onResult(PrintResult result) {
if (result.isFailed()) {
ToastBar.showErrorMessage("Print failed: " + result.getError());
}
}
});
}
Methods
public static boolean isPrintingSupported() | Returns true if the underlying platform can print documents. |
public static void print(String filePath, String mimeType, PrintResultListener listener) | Print a document file through the platform printing system, typically showing the native print dialog. |
public static void printPDF(String filePath, PrintResultListener listener) | Convenience variant of print(String,String,PrintResultListener) for PDF documents. |
public static void printImage(Image image, PrintResultListener listener) | Print an image through the platform printing system. |
Inherited methods
Method details
isPrintingSupported
public static boolean isPrintingSupported()Returns true if the underlying platform can print documents. When
this returns false
print reports PrintResult.STATUS_FAILED to
its listener without showing any UI.public static void print(String filePath, String mimeType, PrintResultListener listener)Print a document file through the platform printing system,
typically showing the native print dialog.
Parameters
filePathString- path of the document in
FileSystemStorage mimeTypeString- the document type, e.g.
application/pdf,image/png listenerPrintResultListener- callback for the print outcome, invoked on the EDT. May be null.
printPDF
public static void printPDF(String filePath, PrintResultListener listener)Convenience variant of
print(String,String,PrintResultListener)
for PDF documents.printImage
public static void printImage(Image image, PrintResultListener listener)Print an image through the platform printing system. The image is
encoded to a temporary PNG file that is deleted once the print flow
finishes.
Parameters
imageImage- the image to print
listenerPrintResultListener- callback for the print outcome, invoked on the EDT. May be null.