我有一个小型测试类来在 JPanel 中呈现 PDF。每当我执行它时,它都会告诉我无论我选择哪种 PDF 都不支持该 PDF。我的代码是:
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
public class TestPDF {
JFrame mainFrame;
final Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TestPDF window = new TestPDF();
window.mainFrame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public TestPDF() {
mainFrame = new JFrame();
mainFrame.setTitle("Test");
mainFrame.setSize(new Dimension((int) (SCREEN_SIZE.getWidth() / 2), (int) (SCREEN_SIZE.getHeight() / 2)));
JScrollPane contentPane = new JScrollPane();
mainFrame.add(contentPane);
SwingController controller = new SwingController();
SwingViewBuilder factory = new SwingViewBuilder(controller);
JPanel viewerComponentPanel = factory.buildViewerPanel();
controller.getDocumentViewController().setAnnotationCallback(new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));
try{
controller.openDocument("gcc.pdf"); //GCC manual
} catch (Exception e){
e.printStackTrace();
}
contentPane.add(viewerComponentPanel);
}
}
我正在尝试加载GCC 手册作为测试。
编辑1:
我正在使用 ICEpdf 6.2.2,在运行课程时,会打开一个弹出窗口,其中说明ICEpdf could not open the specified file at gcc.pdf The file may be corrupt or not a supported file type.