JavaFX: Display PDF in WebView

為{幸葍}努か 提交于 2019-12-20 03:12:46

问题


I need to display a PDF inside the default WebView of JavaFX. I assumed, that i would easily be able to do that like this.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class ShowPdfTest extends Application {
    public static void main(String[] args) {
        launch();
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        WebView webView = new WebView();
        WebEngine engine = webView.getEngine();
        Scene scene = new Scene(webView);
        primaryStage.setScene(scene);
        primaryStage.show();

//        engine.load("https://www.google.com");
        engine.load("http://www.orimi.com/pdf-test.pdf");
    }
}

I was wrong. Nothing happens. It seems like the WebEngine has no built-in PDF-Renderer. I tried JxBrowser which worked fine, but is a rather costly alternative.

So is there any way to display a PDF directly inside the default WebView component?


回答1:


JxBrowser which worked fine, but is a rather costly alternative.

If you your application is an open-source project, you can obtain the JxBrowser Open-Source license here.



来源:https://stackoverflow.com/questions/45062293/javafx-display-pdf-in-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!