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.