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.
(在JxBrowser 6.2中,对公共API进行了一些更改。这些更改可能需要您将更改应用于应用程序的源代码。本简短指南介绍了如何将使用JxBrowser 6.1.1 API编写的应用程序源代码更改为JxBrowser 6.2 API。)


Print to PDF(列印成PDF)

6.1.1(6.1.1)

To print currently loaded web page to PDF document, in JxBrowser 6.1.1 the Browser.printToPDF() method is used. This method prints web page to PDF document with predefined settings. The following code demonstrates how to print web page to PDF and get notification when printing has been finished:(要将当前加载的网页打印为PDF文档,在JxBrowser 6.1.1中使用Browser.printToPDF()方法。此方法使用预定义的设置将网页打印到PDF文档。以下代码演示了如何将网页打印为PDF并在完成打印后获得通知:)

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

6.2(6.2)

In JxBrowser 6.2 we extended Printing API and added functionality that allows deciding whether web page should be printed using printer device or saved as PDF document. We removed Browser.printToPDF() method. Now, you must decide in your PrintHandler implementation whether web page should be saved as PDF or printed using printer device. The following code demonstrates how to handle printing, tell Chromium to save web page as PDF document with the given print settings, get notification when printing has been finished:(在JxBrowser 6.2中,我们扩展了Printing API并添加了功能,该功能允许决定是使用打印机设备打印网页还是另存为PDF文档。我们删除了Browser.printToPDF()方法。现在,您必须在PrintHandler实现中决定是将网页保存为PDF还是使用打印机设备打印。以下代码演示了如何进行打印,告诉Chromium使用给定的打印设置将网页另存为PDF文档,并在完成打印后获得通知:)

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();