Interface PrintPdfCallback
- All Superinterfaces:
AsyncCallback<PrintPdfCallback.Params,
,PrintPdfCallback.Action> BrowserAsyncCallback<PrintPdfCallback.Params,
,PrintPdfCallback.Action> BrowserCallback
,Callback
public interface PrintPdfCallback
extends BrowserAsyncCallback<PrintPdfCallback.Params,PrintPdfCallback.Action>
This callback allows you to configure the print settings when printing PDF content.
To configure settings for printing HTML content use PrintHtmlCallback
.
In this callback you can configure the print settings. The workflow is the following:
- Find the required printer using the
Printers
interface. You can obtain an instance ofPrinters
using thePrintPdfCallback.Params.printers()
method. - Get the current
PrintJob
from the printer. - Configure the required settings for the print job using the
PrintSettings
interface 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:
PrintPdfCallback.Action.proceed(Printer)
.
The following example demonstrates a typical scenario:
browser.set(PrintPdfCallback.class, (params, tell) -> {
SystemPrinter<PdfSettings> printer = params.printers().list().stream()
.filter(p -> p.deviceName().equals("Microsoft XPS Document Writer"))
.findFirst()
.orElseThrow(() -> new IllegalStateException("The printer is not found."));
PrintJob<PdfSettings> printJob = printer.printJob();
printJob.settings()
.paperSize(ISO_A4)
.enableCollatePrinting()
.colorModel(COLOR)
.apply();
printJob.on(PrintCompleted.class, event ->
System.out.println("Printing is completed: success = " + event.isSuccess()));
tell.proceed(printer);
});
Use the PrintPdfCallback.Action.cancel()
method to cancel printing.
- Since:
- 7.13
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final class
An action providing a response to thePrintPdfCallback
.static interface
The parameters of thePrintPdfCallback
. -
Method Summary
Methods inherited from interface com.teamdev.jxbrowser.callback.AsyncCallback
on