无法使用ICEpdf打开远程pdf

  • 本文关键字:pdf ICEpdf java icepdf
  • 更新时间 :
  • 英文 :


我正在尝试使用ICEpdf在JFrame中显示远程pdf。我从他们的网站上复制了代码开始,它是:

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);
}
}

但我得到了以下错误:

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打开远程文件,但当我试图通过程序打开它时,它失败了。

谢谢!

Okk。没有得到任何帮助。所以我决定自己做。你哪儿也得不到。甚至在他们的文件中。因此,这就是使用icepdf打开远程pdf文件所需要做的。

try{URL url=new URL("http://www.orimi.com/pdf-test.pdf");
controller.openDocument(url);

我意识到SwingController类中有两个重载方法,一个以字符串作为参数(用于打开本地pdf文件(,另一个用于打开远程pdf,它接受URL对象。

最新更新