New version is available You are viewing the documentation for JxBrowser 6 which is not supported since December 2019. Go to the current documentation.
List icon 目录

In JxBrowser 6.2 several changes to public API have been introduced. These changes may require that you apply changes to your application’s source code. This short guide shows how to change your application’s source code written with JxBrowser 6.1.1 API to JxBrowser 6.2 API.

6.1.1

To print a currently loaded web page to PDF document, in JxBrowser 6.1.1 the Browser.printToPDF() method is used. This method prints a web page to a PDF document with the predefined settings. The following code demonstrates how to print a web page to PDF and get a notification when printing has been finished:

browser.printToPDF("web_page.pdf", new PrintJobListener() {
    @Override
    public void onPrintingDone(PrintJobEvent event) {
    }
});

6.2

In JxBrowser 6.2 we extended Printing API and added a functionality that allows deciding whether a web page should be printed using a printer device or saved as a PDF document. We removed Browser.printToPDF() method. Now, you need to decide in your PrintHandler implementation whether a web page should be saved as PDF or printed using a printer device. The following code demonstrates how to handle printing, tell Chromium to save a web page as a PDF document with the given print settings, get a notification when printing has been finished:

browser.setPrintHandler(new PrintHandler() {
    @Override
    public PrintStatus onPrint(PrintJob printJob) {
        PrintSettings settings = printJob.getPrintSettings();
        settings.setPrintToPDF(true);
        settings.setPDFFilePath("web_page.pdf");
        settings.setPrintBackgrounds(true);
        printJob.addPrintJobListener(new PrintJobListener() {
            @Override
            public void onPrintingDone(PrintJobEvent event) {
            }
        });
        return PrintStatus.CONTINUE;
    }
});

browser.print();
Go Top