我试图在JFrame中使用ICEpdf显示一个远程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打开远程文件,就像他们的文档中所说的那样,但是当我试图通过程序打开它时,它就失败了。
谢谢!
发布于 2020-04-24 12:17:52
好的。得不到帮助。所以我决定自己去做。你哪儿也得不到。即使在他们的文件里。这就是使用icepdf打开远程pdf文件所需要做的事情。
try{URL url=new URL("http://www.orimi.com/pdf-test.pdf");
controller.openDocument(url);我意识到在SwingController类中有两种重载方法,一种以字符串作为论证(用于打开本地pdf文件),另一种用于打开远程pdfs,后者接受一个URL对象。
https://stackoverflow.com/questions/61407713
复制相似问题