【问题标题】:Opening PDF in JFrame在 JFrame 中打开 PDF
【发布时间】:2015-04-04 10:06:42
【问题描述】:

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

【问题讨论】:

  • 对于 PDFBox,获取源代码并查看 PDFReader.java 和 PDFPagePanel.java。但我想说你的问题相当广泛,很可能会被标记。
  • 您可以使用PDPage类的方法convertToImage,然后在JFrame上显示图像。

标签: java swing itext pdfbox icepdf


【解决方案1】:
  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。 注意:在你的类路径中包含 ICEPDF jar (icepdf-viewer.jar,icepdf-core.jar ) http://www.icesoft.org/java/downloads/icepdf-downloads.jsf

【讨论】:

  • 嘿,你能告诉我如何使用它打开远程 pdf。当我将 URL 放入文件时,我收到一条消息,即 icepdf 无法打开文件,因为它已损坏,文件格式不正确,即使 pdf 很好。
  • 你用的是哪个版本@Nesh?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-15
  • 1970-01-01
  • 1970-01-01
  • 2014-04-08
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多