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);
}
Aggregations