原創|產品更新|編輯:李顯亮|2021-03-02 09:59:24.797|閱讀 944 次
概述:JAVA應用程序瀏覽器集成控件JxBrowser更新至7.13, 在此版本中,Chromium引擎已升級到版本88,支持macOS Big Sur,引入了期待已久的打印API,歡迎下載體驗。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
JxBrowser是將基于Chromium的瀏覽器與Java應用程序集成,以處理和顯示HTML5、CSS3、JavaScript、Flash等。
近日,JxBrowser v7.13發布啦! 在此版本中,Chromium引擎已升級到版本88,支持macOS Big Sur,引入了期待已久的打印API,允許以編程方式打印網頁和PDF,歡迎下載體驗。
新增功能
Chromium 88
Chromium已更新至版本88.0.4324.182。在此Chromium構建中,其與JxBrowser封裝在一起的某些功能已被刪除或更改,因此jxbrowser的庫版本在公共API中引入了一些重大更改。
macOS Big Sur
現在可以在基于英特爾的Mac上的macOS Big Sur上運行JxBrowser了。同時計劃在下一個版本中引入對 Apple Silicon M1 架構的支持。現在可以在 Rosetta 2 仿真模式下使用 JxBrowser。
打印API
現在,可以以編程方式打印網頁或PDF文檔,而無需顯示“打印預覽”對話框。使用新的打印API,可以:
下面的示例演示如何將當前加載的網頁另存為PDF:
Browser browser = engine.newBrowser(); CountDownLatch latch = new CountDownLatch(1); // Allow printing web pages programmatically browser.set(PrintCallback.class, (params, tell) -> tell.print()); // When a web page is about to print, configure the print settings and proceed browser.set(PrintHtmlCallback.class, (params, tell) -> { // Select PDF printer as the target device PdfPrinter<HtmlSettings> pdfPrinter = params.printers().pdfPrinter(); // Access the print job to configure its settings and register events PrintJob<HtmlSettings> printJob = pdfPrinter.printJob(); // Listen to the print completed event printJob.on(PrintCompleted.class, event -> latch.countDown()); // Configure the required print settings including path to the target PDF file printJob.settings() .pdfFilePath(Paths.get("/Users/vladimir/Desktop/google.pdf")) .apply(); // Notify the engine that we want to print using the given PDF printer tell.proceed(pdfPrinter); }); // Load web page and wait until it's loaded completely browser.navigation().loadUrlAndWait("http://google.com"); // Print the currently loaded web page browser.mainFrame().ifPresent(Frame::print); // Await until printing has been completed if (latch.await(30, TimeUnit.SECONDS)) { throw new IllegalStateException("Failed to save web page as PDF within 30 sec"); }
定制方案
攔截請求的方式得到了改進。要使用自定義jxb方案攔截URL請求,請添加相應的方案,并將其與攔截回調相關聯,如下例所示:
EngineOptions.Builder optionsBuilder = EngineOptions.newBuilder(OFF_SCREEN); optionsBuilder.addScheme(Scheme.of("jxb"), params -> { UrlRequestJob job = params.newUrlRequestJob( UrlRequestJob.Options.newBuilder(HttpStatus.OK) .addHttpHeader(HttpHeader.of("Content-Type", "text/html")) .build()); job.write("<html><body>Hello!</body></html>".getBytes(UTF_8)); job.complete(); return Response.intercept(job); }); Engine engine = Engine.newInstance(optionsBuilder.build());
現在,如果加載jxb://anyhost/anypage.html,則將攔截URL請求,并調用關聯的回調。將獲得以下輸出:
外部應用
操作系統中安裝的某些應用程序可能與特定的URI方案相關聯。當用戶使用與已安裝的應用程序關聯的方案導航到URL時,Chromium將顯示一個對話框,用戶可以在其中確定是否應在關聯的外部應用程序中打開鏈接。
在此更新中,引入了回調,可以使用該回調來攔截此類情況并向最終用戶顯示您自己的對話框,或者以編程方式打開外部應用程序而不會提示用戶。例如:
browser.set(OpenExternalAppCallback.class, (params, tell) -> tell.open());
創建Swing,JavaFX和SWTBrowserView實例時,此回調將自動注冊(如果尚未注冊),并顯示相應的對話框:
改進
Bug修復
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn