Interface PrintHtmlCallback
- All Superinterfaces:
AsyncCallback<PrintHtmlCallback.Params,,PrintHtmlCallback.Action> BrowserAsyncCallback<PrintHtmlCallback.Params,,PrintHtmlCallback.Action> BrowserCallback,Callback
public interface PrintHtmlCallback
extends BrowserAsyncCallback<PrintHtmlCallback.Params,PrintHtmlCallback.Action>
This callback allows you to configure the print settings when printing HTML content.
To configure settings for printing PDF content use PrintPdfCallback.
In this callback you can configure the print settings. The workflow is the following:
- Find the required printer using the
Printersinterface. You can obtain an instance ofPrintersusing thePrintHtmlCallback.Params.printers()method. - Get the current
PrintJobfrom the printer. - Configure the required settings for the print job using the
PrintSettingsinterface provided by thePrintJob.settings()method. - Apply the configured settings using the
PrintSettings.apply()method. - Tell the browser to proceed with the printing using the configured settings:
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.
- Since:
- 7.13
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classAn action providing a response to thePrintHtmlCallback.static interfaceThe parameters of thePrintHtmlCallback. -
Method Summary
Methods inherited from interface com.teamdev.jxbrowser.callback.AsyncCallback
on