开源PDFViewer Javafx

时间:2018-01-30 14:24:30

标签: pdf javafx pdf-viewer

我想在我的javafx应用程序中显示一个pdf文件。直到现在我已经尝试了许多没有运气的东西,包括pdf.js html pdf viewer但是我得到了以下异常:

 Caused by: netscape.javascript.JSException: SyntaxError: Invalid character '\u8216'

有人知道任何更简单的方法,这应该是免费和开源的。感谢。

1 个答案:

答案 0 :(得分:2)

我刚创建了一个可以查看的应用。 Here。您可能会找到一个将PDF转换为HTML的免费应用程序。此转换是使用https://www.idrsolutions.com/online-pdf-to-html5-converter/完成的。我个人使用Acrobat Reader来转换我的文件,目前我正在尝试实现我希望我的应用程序拥有的所有不同功能。

import java.io.File;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

/**
 *
 * @author blj0011
 */
public class PDFToHTMLExampleApp extends Application
{

    @Override
    public void start(Stage primaryStage)
    {
        File file = new File("CookBook/index.html");

        WebView webView = new WebView();
        WebEngine webEngine = webView.getEngine();
        webEngine.load(file.toURI().toString());

        StackPane root = new StackPane();
        root.getChildren().add(webView);

        Scene scene = new Scene(root, 700, 1000);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        launch(args);
    }

}

我选择此网站进行转换的原因是它们已经具有缩放功能和处理页面的功能。失败的原因是他们已经禁用了搜索功能。 enter image description here