Search in sources :

Example 1 with HtmlSettings

use of com.teamdev.jxbrowser.print.SystemPrinter.HtmlSettings in project JxBrowser-Examples by TeamDev-IP.

the class PrintSettings method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(HARDWARE_ACCELERATED);
    Browser browser = engine.newBrowser();
    browser.set(PrintCallback.class, (params, tell) -> tell.print());
    // #docfragment "Callback"
    browser.set(PrintHtmlCallback.class, (params, tell) -> {
        // #docfragment "Configure settings"
        SystemPrinter<HtmlSettings> printer = params.printers().defaultPrinter().orElseThrow(IllegalStateException::new);
        PrintJob<HtmlSettings> printJob = printer.printJob();
        printJob.settings().paperSize(ISO_A4).colorModel(COLOR).enablePrintingBackgrounds().disablePrintingHeaderFooter().orientation(PORTRAIT).apply();
        // #enddocfragment "Configure settings"
        // #docfragment "Subscribe to PrintCompleted"
        printJob.on(PrintCompleted.class, event -> {
            if (event.isSuccess()) {
                System.out.println("Printing is completed successfully.");
            } else {
                System.out.println("Printing has failed.");
            }
        });
        // #enddocfragment "Subscribe to PrintCompleted"
        // #docfragment "Proceed"
        tell.proceed(printer);
    // #enddocfragment "Proceed"
    });
    // #enddocfragment "Callback"
    browser.navigation().loadUrlAndWait("https://google.com");
    browser.mainFrame().ifPresent(Frame::print);
}
Also used : Frame(com.teamdev.jxbrowser.frame.Frame) HtmlSettings(com.teamdev.jxbrowser.print.SystemPrinter.HtmlSettings) Engine(com.teamdev.jxbrowser.engine.Engine) Browser(com.teamdev.jxbrowser.browser.Browser)

Aggregations

Browser (com.teamdev.jxbrowser.browser.Browser)1 Engine (com.teamdev.jxbrowser.engine.Engine)1 Frame (com.teamdev.jxbrowser.frame.Frame)1 HtmlSettings (com.teamdev.jxbrowser.print.SystemPrinter.HtmlSettings)1