Search in sources :

Example 1 with HtmlSettings

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

the class PrintToPdf method main.

public static void main(String[] args) {
    Engine engine = Engine.newInstance(OFF_SCREEN);
    Browser browser = engine.newBrowser();
    browser.set(PrintCallback.class, (params, tell) -> tell.print());
    browser.set(PrintHtmlCallback.class, (params, tell) -> {
        PdfPrinter<PdfPrinter.HtmlSettings> pdfPrinter = params.printers().pdfPrinter();
        PrintJob<HtmlSettings> printJob = pdfPrinter.printJob();
        printJob.settings().pdfFilePath(Paths.get("google.pdf").toAbsolutePath()).enablePrintingBackgrounds().orientation(PORTRAIT).apply();
        printJob.on(PrintCompleted.class, event -> {
            if (event.isSuccess()) {
                System.out.println("Printing is completed successfully.");
            } else {
                System.out.println("Printing has failed.");
            }
        });
        tell.proceed(pdfPrinter);
    });
    browser.navigation().loadUrlAndWait("https://google.com");
    browser.mainFrame().ifPresent(Frame::print);
}
Also used : Frame(com.teamdev.jxbrowser.frame.Frame) HtmlSettings(com.teamdev.jxbrowser.print.PdfPrinter.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.PdfPrinter.HtmlSettings)1