使用PDF表单作为Java UI

时间:2014-11-06 18:13:19

标签: java swing itext


我已经看到使用iText可以创建交互式PDF表单(http://itextpdf.com/book/chapter.php?id=8)。这很有意思,我想知道是否可以从Java Desktop应用程序中填充PDF表单。 最后,我需要知道是否可以从Java应用程序中打开PDF文件。可能吗 ?
感谢

1 个答案:

答案 0 :(得分:2)

您可以考虑使用OpenSource版和专业版中提供的ICEPDF。以下示例摘自文档,显示如何在JPanel中显示PDF:

String filePath = "somefilepath/myfile.pdf";

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

// Build a SwingViewFactory configured with the controller
SwingViewBuilder factory = new SwingViewBuilder(controller);

// Use the factory to build a JPanel that is pre-configured
//with a complete, active Viewer UI.
JPanel viewerComponentPanel = factory.buildViewerPanel();

// add copy keyboard command
ComponentKeyBinding.install(controller, viewerComponentPanel);

// add interactive mouse link annotation support via callback
controller.getDocumentViewController().setAnnotationCallback(
      new org.icepdf.ri.common.MyAnnotationCallback(
             controller.getDocumentViewController()));

// Create a JFrame to display the panel in
JFrame window = new JFrame("Using the Viewer Component");
window.getContentPane().add(viewerComponentPanel);
window.pack();
window.setVisible(true);

// Open a PDF document to view
controller.openDocument(filePath);