Javafx Pdf查看器不加载pdf

时间:2018-12-21 16:47:11

标签: java css pdf javafx icepdf

我已经基于https://blog.samirhadzic.com/2017/02/09/show-pdf-in-your-application/在我的javaFX应用程序中实现了pdfviewer。但是,它不会加载任何pdf。 pdf查看器显示一个错误:

  

PDF.js v2.0.943(内部版本:dc98bf76)   消息:输入错误

我尝试了多个pdf,但它们没有损坏。

engine = web.getEngine();
String url = getClass().getResource("resources/web/viewer.html").toExternalForm();

engine.setUserStyleSheetLocation(getClass().getResource("web.css").toExternalForm());

engine.setJavaScriptEnabled(true);
engine.load(url);

engine.getLoadWorker()
      .stateProperty()
      .addListener((observable, oldValue, newValue) -> {

          JSObject window = (JSObject) engine.executeScript("window");
          window.setMember("java", new JSLogListener());
          engine.executeScript("console.log = function(message){ java.log(message); };");

          if (newValue == Worker.State.SUCCEEDED) {
                try {
                     byte[] data = FileUtils.readFileToByteArray(new File("C:/werkruimte/123.pdf"));
                     String base64 = Base64.getEncoder().encodeToString(data);

                     engine.executeScript("openFileFromBase64('" + base64 + "')");
                } catch (Exception e) {
                     e.printStackTrace();
                }
          }
    }); 

0 个答案:

没有答案