首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用ICEpdf打开远程pdf

无法使用ICEpdf打开远程pdf
EN

Stack Overflow用户
提问于 2020-04-24 11:51:53
回答 1查看 484关注 0票数 0

我试图在JFrame中使用ICEpdf显示一个远程pdf。我从他们的网站上复制代码开始,即:

代码语言:javascript
复制
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.common.MyAnnotationCallback;

import javax.swing.*;
class ViewerComponentExample {
    public static void main(String[] args) {
        // Get a file from the command line to open
        String filePath = "http://www.orimi.com/pdf-test.pdf";

        // build a component controller
        SwingController controller = new SwingController();

        SwingViewBuilder factory = new SwingViewBuilder(controller);

        JPanel viewerComponentPanel = factory.buildViewerPanel();


        JFrame applicationFrame = new JFrame();
        applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        applicationFrame.getContentPane().add(viewerComponentPanel);

        // Now that the GUI is all in place, we can try openning a PDF
        controller.openDocument(filePath);

        // show the component
        applicationFrame.pack();
        applicationFrame.setVisible(true);
    }
}

但我得到了以下错误:

代码语言:javascript
复制
ICEpdf could not open the specified file at http://www.icepdf.org/resources/DevelopersGuide.pdf. 
The file may be corrupted or not a supported file type.

我使用icepdf-core.jar和icepdf-viewer.jar。我需要其他jar文件来打开远程pdf吗?我也无法在他们的论坛上提出任何问题。我看不出有什么链接可以问我自己的问题。

如果有人用过这个东西,请告诉我如何解决这个错误。

编辑

我能够使用命令java org.icepdf.ri.viewer.Main -loadurl http://www.orimi.com/pdf-test.pdf打开远程文件,就像他们的文档中所说的那样,但是当我试图通过程序打开它时,它就失败了。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-04-24 12:17:52

好的。得不到帮助。所以我决定自己去做。你哪儿也得不到。即使在他们的文件里。这就是使用icepdf打开远程pdf文件所需要做的事情。

代码语言:javascript
复制
try{URL url=new URL("http://www.orimi.com/pdf-test.pdf");
   controller.openDocument(url);

我意识到在SwingController类中有两种重载方法,一种以字符串作为论证(用于打开本地pdf文件),另一种用于打开远程pdfs,后者接受一个URL对象。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61407713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档