public interface PrintHtmlCallback extends BrowserAsyncCallback<PrintHtmlCallback.Params,PrintHtmlCallback.Action>
To configure settings for printing PDF content use PrintPdfCallback.
In this callback you can configure the print settings. The workflow is the following:
Printers interface. You can obtain an
instance of Printers using the PrintHtmlCallback.Params.printers() method.
PrintJob from the printer.
PrintSettings interface provided by the
PrintJob.settings() method.
PrintSettings.apply() method.
PrintHtmlCallback.Action.proceed(Printer).
The following example demonstrates a typical scenario:
browser.set(PrintHtmlCallback.class, (params, tell) -> {
SystemPrinter<HtmlSettings> printer = params.printers().list().stream()
.filter(p -> p.deviceName().equals("Microsoft XPS Document Writer"))
.findFirst()
.orElseThrow(() -> new IllegalStateException("The printer is not found."));
PrintJob<HtmlSettings> printJob = printer.printJob();
printJob.settings()
.paperSize(ISO_A4)
.enablePrintingHeaderFooter()
.colorModel(BLACK)
.apply();
printJob.on(PrintCompleted.class, event ->
System.out.println("Printing is completed: success = " + event.isSuccess()));
tell.proceed(printer);
});
Use the PrintHtmlCallback.Action.cancel() method to cancel printing.
| Modifier and Type | Interface and Description |
|---|---|
static class |
PrintHtmlCallback.Action
An action providing a response to the
PrintHtmlCallback. |
static interface |
PrintHtmlCallback.Params
The parameters of the
PrintHtmlCallback. |
on