Class 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());
}
}
});
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReturns true if the underlying platform can print documents.static voidprint(String filePath, String mimeType, PrintResultListener listener) Print a document file through the platform printing system, typically showing the native print dialog.static voidprintImage(Image image, PrintResultListener listener) Print an image through the platform printing system.static voidprintPDF(String filePath, PrintResultListener listener) Convenience variant ofprint(String,String,PrintResultListener)for PDF documents.
-
Method Details
-
isPrintingSupported
public static boolean isPrintingSupported()Returns true if the underlying platform can print documents. When this returns falseprint(String, String, PrintResultListener)reportsPrintResult.STATUS_FAILEDto its listener without showing any UI. -
print
Print a document file through the platform printing system, typically showing the native print dialog.
Parameters
-
filePath: path of the document inFileSystemStorage -
mimeType: the document type, e.g.application/pdf,image/png -
listener: callback for the print outcome, invoked on the EDT. May be null.
-
-
printPDF
Convenience variant ofprint(String,String,PrintResultListener)for PDF documents. -
printImage
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
-
image: the image to print -
listener: callback for the print outcome, invoked on the EDT. May be null.
-
-