在JFrame中打开PDF

时间:2015-04-04 10:06:42

标签: java swing itext pdfbox icepdf

我正在使用java制作PDF阅读器,我想在自己的应用程序的JFrame中打开PDF文件,以便我可以创建自己的功能。有没有办法做到这一点? 我正在使用" iText"," pdfBox"和" ICEpdf"操纵PDF文档。

1 个答案:

答案 0 :(得分:2)

  public static void pdfViewerICE() {
        String filePath = "PDF_URL";
        // build a controller
        controller = new SwingController();

        // Build a SwingViewFactory configured with the controller
        SwingViewBuilder factory = new SwingViewBuilder(controller);
           PropertiesManager properties = new PropertiesManager(
                System.getProperties(),
                 ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));

   properties.set(PropertiesManager.PROPERTY_DEFAULT_ZOOM_LEVEL, "1.75");

        // Use the factory to build a JPanel that is pre-configured
        //with a complete, active Viewer UI.
       JPanel viewerComponentPanel = factory.buildViewerPanel();

        controller.openDocument(filePath);
      }

上面的代码通过您的java程序使用ICEPDF打开PDF。 注意:在类路径http://www.icesoft.org/java/downloads/icepdf-downloads.jsf中包含ICEPDF jar(icepdf-viewer.jar,icepdf-core.jar)